From c5aaf923d80e9f71e0c93d7d99dc1e2f83d7acbf Mon Sep 17 00:00:00 2001 From: James Zern Date: Fri, 13 Dec 2013 19:03:08 -0800 Subject: [PATCH] webmdec/tests: fix leak when file isn't read to eof the nestegg packet was only freed by subsequent reads Change-Id: Ib687a13907861c7575830783e47a596d85169cf1 --- test/webm_video_source.h | 10 ++++++++-- webmdec.c | 9 +++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/test/webm_video_source.h b/test/webm_video_source.h index 9fc854593..53b0ba2b4 100644 --- a/test/webm_video_source.h +++ b/test/webm_video_source.h @@ -90,8 +90,12 @@ class WebMVideoSource : public CompressedVideoSource { virtual ~WebMVideoSource() { if (input_file_) fclose(input_file_); - if (nestegg_ctx_) + if (nestegg_ctx_ != NULL) { + if (pkt_ != NULL) { + nestegg_free_packet(pkt_); + } nestegg_destroy(nestegg_ctx_); + } } virtual void Init() { @@ -136,8 +140,10 @@ class WebMVideoSource : public CompressedVideoSource { do { /* End of this packet, get another. */ - if (pkt_) + if (pkt_ != NULL) { nestegg_free_packet(pkt_); + pkt_ = NULL; + } int again = nestegg_read_packet(nestegg_ctx_, &pkt_); ASSERT_GE(again, 0) << "nestegg_read_packet failed"; diff --git a/webmdec.c b/webmdec.c index 4bf7c7e2b..0c75d7a2c 100644 --- a/webmdec.c +++ b/webmdec.c @@ -117,8 +117,10 @@ int webm_read_frame(struct WebmInputContext *webm_ctx, do { /* End of this packet, get another. */ - if (webm_ctx->pkt) + if (webm_ctx->pkt) { nestegg_free_packet(webm_ctx->pkt); + webm_ctx->pkt = NULL; + } if (nestegg_read_packet(webm_ctx->nestegg_ctx, &webm_ctx->pkt) <= 0 || nestegg_packet_track(webm_ctx->pkt, &track)) { @@ -188,6 +190,9 @@ int webm_guess_framerate(struct WebmInputContext *webm_ctx, } void webm_free(struct WebmInputContext *webm_ctx) { - if (webm_ctx && webm_ctx->nestegg_ctx) + if (webm_ctx && webm_ctx->nestegg_ctx) { + if (webm_ctx->pkt) + nestegg_free_packet(webm_ctx->pkt); nestegg_destroy(webm_ctx->nestegg_ctx); + } }