Fix a free on invalid ptr when img allocation fails

BUG=aomedia:2998

Change-Id: Ib1eda3b2379fb32f0cdbbf6e7938966efdb2bab9
diff --git a/aom/src/aom_image.c b/aom/src/aom_image.c
index dfdee87..13f71b2 100644
--- a/aom/src/aom_image.c
+++ b/aom/src/aom_image.c
@@ -38,6 +38,8 @@
   unsigned int h, w, s, xcs, ycs, bps, bit_depth;
   unsigned int stride_in_bytes;
 
+  if (img != NULL) memset(img, 0, sizeof(aom_image_t));
+
   /* Treat align==0 like align==1 */
   if (!buf_align) buf_align = 1;
 
@@ -111,8 +113,6 @@
     if (!img) goto fail;
 
     img->self_allocd = 1;
-  } else {
-    memset(img, 0, sizeof(aom_image_t));
   }
 
   img->img_data = img_data;