aomdec: avoid memory leaks

This is a manual cherry-pick from libvpx/master:
e61d82bd4fab408b32011568a52524b6a82bcf25

Change-Id: I29bbcea604507d016d4783c7ed1697712814478d
diff --git a/aomdec.c b/aomdec.c
index e88c81f..42ae91b 100644
--- a/aomdec.c
+++ b/aomdec.c
@@ -490,6 +490,7 @@
   aom_codec_ctx_t decoder;
   char *fn = NULL;
   int i;
+  int ret = EXIT_FAILURE;
   uint8_t *buf = NULL;
   size_t bytes_in_buffer = 0, buffer_size = 0;
   FILE *infile;
@@ -706,7 +707,7 @@
                          dec_flags)) {
     fprintf(stderr, "Failed to initialize decoder: %s\n",
             aom_codec_error(&decoder));
-    return EXIT_FAILURE;
+    goto fail2;
   }
 
   if (!quiet) fprintf(stderr, "%s\n", decoder.name);
@@ -716,13 +717,13 @@
     if (aom_codec_control(&decoder, AV1_SET_DECODE_TILE_ROW, tile_row)) {
       fprintf(stderr, "Failed to set decode_tile_row: %s\n",
               aom_codec_error(&decoder));
-      return EXIT_FAILURE;
+      goto fail;
     }
 
     if (aom_codec_control(&decoder, AV1_SET_DECODE_TILE_COL, tile_col)) {
       fprintf(stderr, "Failed to set decode_tile_col: %s\n",
               aom_codec_error(&decoder));
-      return EXIT_FAILURE;
+      goto fail;
     }
   }
 #endif
@@ -742,7 +743,7 @@
                                              &ext_fb_list)) {
       fprintf(stderr, "Failed to configure external frame buffers: %s\n",
               aom_codec_error(&decoder));
-      return EXIT_FAILURE;
+      goto fail;
     }
   }
 
@@ -851,7 +852,7 @@
                   "Scaling is disabled in this configuration. "
                   "To enable scaling, configure with --enable-libyuv\n",
                   aom_codec_error(&decoder));
-          return EXIT_FAILURE;
+          goto fail;
 #endif
         }
       }
@@ -968,17 +969,21 @@
     fprintf(stderr, "\n");
   }
 
-  if (frames_corrupted)
+  if (frames_corrupted) {
     fprintf(stderr, "WARNING: %d frames corrupted.\n", frames_corrupted);
+  } else {
+    ret = EXIT_SUCCESS;
+  }
 
 fail:
 
   if (aom_codec_destroy(&decoder)) {
     fprintf(stderr, "Failed to destroy decoder: %s\n",
             aom_codec_error(&decoder));
-    return EXIT_FAILURE;
   }
 
+fail2:
+
   if (!noblit && single_file) {
     if (do_md5) {
       MD5Final(md5_digest, &md5_ctx);
@@ -1008,7 +1013,7 @@
   fclose(infile);
   free(argv);
 
-  return frames_corrupted ? EXIT_FAILURE : EXIT_SUCCESS;
+  return ret;
 }
 
 int main(int argc, const char **argv_) {