obudec,file_is_obu: fix leak on failure
Bug: aomedia:3334
Fixed: aomedia:3334
Change-Id: I839659b268a6b30fd9ff220be843b16eaaa2c23a
diff --git a/common/obudec.c b/common/obudec.c
index 650f997..87dd113 100644
--- a/common/obudec.c
+++ b/common/obudec.c
@@ -350,6 +350,7 @@
if (payload_length > (obu_ctx->buffer_capacity - bytes_read)) {
fprintf(stderr, "obudec: First OBU's payload is too large\n");
rewind(f);
+ obudec_free(obu_ctx);
return 0;
}
@@ -358,6 +359,7 @@
f, payload_length, &obu_ctx->buffer[bytes_read], &payload_bytes);
if (status < 0) {
rewind(f);
+ obudec_free(obu_ctx);
return 0;
}
obu_ctx->bytes_buffered += payload_bytes;
@@ -483,4 +485,9 @@
return 0;
}
-void obudec_free(struct ObuDecInputContext *obu_ctx) { free(obu_ctx->buffer); }
+void obudec_free(struct ObuDecInputContext *obu_ctx) {
+ free(obu_ctx->buffer);
+ obu_ctx->buffer = NULL;
+ obu_ctx->buffer_capacity = 0;
+ obu_ctx->bytes_buffered = 0;
+}