Fix bug in extend_frame chroma extended too far

This fixes issue 667.

In the case where the frame was an odd number of pixels
wide or high, the border was being extended by one col
or row too far.

The calculation of color plane dimensions was modified
to use those already computed at the time the frame
buffer was allocated.

Also freed the temporary scaling buffer in vpxdec to
prevent a memory leak.

Change-Id: I195bc81d84c0fc5d8260c1232200d62399e4b51f
diff --git a/vpx_scale/generic/yv12extend.c b/vpx_scale/generic/yv12extend.c
index f2aec2b..7896dfe 100644
--- a/vpx_scale/generic/yv12extend.c
+++ b/vpx_scale/generic/yv12extend.c
@@ -84,14 +84,13 @@
 static void extend_frame(YV12_BUFFER_CONFIG *const ybf,
                          int subsampling_x, int subsampling_y,
                          int ext_size) {
-  const int c_w = (ybf->y_crop_width + subsampling_x) >> subsampling_x;
-  const int c_h = (ybf->y_crop_height + subsampling_y) >> subsampling_y;
-  const int c_et = ext_size >> subsampling_y;
-  const int c_el = ext_size >> subsampling_x;
-  const int c_eb = (ext_size + ybf->y_height - ybf->y_crop_height +
-                    subsampling_y) >> subsampling_y;
-  const int c_er = (ext_size + ybf->y_width - ybf->y_crop_width +
-                    subsampling_x) >> subsampling_x;
+  const int c_w = ybf->uv_crop_width;
+  const int c_h = ybf->uv_crop_height;
+  const int c_ext_size = ext_size >> 1;
+  const int c_et = c_ext_size;
+  const int c_el = c_ext_size;
+  const int c_eb = c_ext_size + ybf->uv_height - ybf->uv_crop_height;
+  const int c_er = c_ext_size + ybf->uv_width - ybf->uv_crop_width;
 
   assert(ybf->y_height - ybf->y_crop_height < 16);
   assert(ybf->y_width - ybf->y_crop_width < 16);
diff --git a/vpxdec.c b/vpxdec.c
index 110e4ac..d821143 100644
--- a/vpxdec.c
+++ b/vpxdec.c
@@ -1124,7 +1124,8 @@
 fail:
 
   if (vpx_codec_destroy(&decoder)) {
-    fprintf(stderr, "Failed to destroy decoder: %s\n", vpx_codec_error(&decoder));
+    fprintf(stderr, "Failed to destroy decoder: %s\n",
+            vpx_codec_error(&decoder));
     return EXIT_FAILURE;
   }
 
@@ -1135,6 +1136,9 @@
     nestegg_destroy(input.nestegg_ctx);
   if (input.kind != WEBM_FILE)
     free(buf);
+
+  if (scaled_img) vpx_img_free(scaled_img);
+
   fclose(infile);
   free(argv);