From 3688076d42c64ea93b6805db02c78a1769840954 Mon Sep 17 00:00:00 2001
From: John Koleszar <jkoleszar@google.com>
Date: Thu, 3 Feb 2011 00:26:37 -0500
Subject: [PATCH] dixie: fix memory leaks

Implemented the decoder shutdown call to deallocate buffers when the
codec is destroyed.

Change-Id: I6cd62f40f34e0db91fb7eb8cb673f5d9726fe192
---
 vp8/dixie/dixie.c     |  9 +++++++++
 vp8/dixie/dixie.h     |  4 ++++
 vp8/dixie/modemv.c    | 10 ++++++++++
 vp8/dixie/modemv.h    |  4 ++++
 vp8/dixie/predict.c   | 14 ++++++++++++++
 vp8/dixie/predict.h   |  4 ++++
 vp8/dixie/tokens.c    | 12 ++++++++++++
 vp8/dixie/tokens.h    |  4 ++++
 vp8/vp8_dixie_iface.c |  1 +
 9 files changed, 62 insertions(+)

diff --git a/vp8/dixie/dixie.c b/vp8/dixie/dixie.c
index dd1b2060f6..be3a6a92e2 100644
--- a/vp8/dixie/dixie.c
+++ b/vp8/dixie/dixie.c
@@ -525,3 +525,12 @@ vp8_dixie_decode_frame(struct vp8_decoder_ctx *ctx,
 
     return ctx_->error.error_code;
 }
+
+
+void
+vp8_dixie_decode_destroy(struct vp8_decoder_ctx *ctx)
+{
+    vp8_dixie_predict_destroy(ctx);
+    vp8_dixie_tokens_destroy(ctx);
+    vp8_dixie_modemv_destroy(ctx);
+}
diff --git a/vp8/dixie/dixie.h b/vp8/dixie/dixie.h
index e3e7a95b6c..eab5f2245e 100644
--- a/vp8/dixie/dixie.h
+++ b/vp8/dixie/dixie.h
@@ -315,6 +315,10 @@ void
 vp8_dixie_decode_init(struct vp8_decoder_ctx *ctx);
 
 
+void
+vp8_dixie_decode_destroy(struct vp8_decoder_ctx *ctx);
+
+
 vpx_codec_err_t
 vp8_parse_frame_header(const unsigned char   *data,
                        unsigned int           sz,
diff --git a/vp8/dixie/modemv.c b/vp8/dixie/modemv.c
index cc1f3e5fd6..60ba197f58 100644
--- a/vp8/dixie/modemv.c
+++ b/vp8/dixie/modemv.c
@@ -666,3 +666,13 @@ vp8_dixie_modemv_init(struct vp8_decoder_ctx *ctx)
 
     ctx->mb_info_rows = ctx->mb_info_rows_storage + 1;
 }
+
+
+void
+vp8_dixie_modemv_destroy(struct vp8_decoder_ctx *ctx)
+{
+    free(ctx->mb_info_storage);
+    ctx->mb_info_storage = NULL;
+    free(ctx->mb_info_rows_storage);
+    ctx->mb_info_rows_storage = NULL;
+}
diff --git a/vp8/dixie/modemv.h b/vp8/dixie/modemv.h
index 9afa187e87..75cb5ef9f0 100644
--- a/vp8/dixie/modemv.h
+++ b/vp8/dixie/modemv.h
@@ -14,6 +14,10 @@ void
 vp8_dixie_modemv_init(struct vp8_decoder_ctx *ctx);
 
 
+void
+vp8_dixie_modemv_destroy(struct vp8_decoder_ctx *ctx);
+
+
 void
 vp8_dixie_modemv_process_row(struct vp8_decoder_ctx *ctx,
                              struct bool_decoder    *bool,
diff --git a/vp8/dixie/predict.c b/vp8/dixie/predict.c
index 05da4cd04f..0a5f4cac62 100644
--- a/vp8/dixie/predict.c
+++ b/vp8/dixie/predict.c
@@ -1836,6 +1836,20 @@ vp8_dixie_predict_init(struct vp8_decoder_ctx *ctx)
 }
 
 
+void
+vp8_dixie_predict_destroy(struct vp8_decoder_ctx *ctx)
+{
+    int i;
+
+    for (i = 0; i < NUM_REF_FRAMES; i++)
+    {
+        vpx_img_free(&ctx->frame_strg[i].img);
+        ctx->frame_strg[i].ref_cnt = 0;
+        ctx->ref_frames[i] = NULL;
+    }
+}
+
+
 void
 vp8_dixie_predict_process_row(struct vp8_decoder_ctx *ctx,
                               unsigned int            row,
diff --git a/vp8/dixie/predict.h b/vp8/dixie/predict.h
index 1eee757696..7e3a9c29ce 100644
--- a/vp8/dixie/predict.h
+++ b/vp8/dixie/predict.h
@@ -14,6 +14,10 @@ void
 vp8_dixie_predict_init(struct vp8_decoder_ctx *ctx);
 
 
+void
+vp8_dixie_predict_destroy(struct vp8_decoder_ctx *ctx);
+
+
 void
 vp8_dixie_predict_process_row(struct vp8_decoder_ctx *ctx,
                               unsigned int            row,
diff --git a/vp8/dixie/tokens.c b/vp8/dixie/tokens.c
index 4a73be0a91..787aa202c2 100644
--- a/vp8/dixie/tokens.c
+++ b/vp8/dixie/tokens.c
@@ -479,3 +479,15 @@ vp8_dixie_tokens_init(struct vp8_decoder_ctx *ctx)
             vpx_internal_error(&ctx->error, VPX_CODEC_MEM_ERROR, NULL);
     }
 }
+
+
+void
+vp8_dixie_tokens_destroy(struct vp8_decoder_ctx *ctx)
+{
+    int i;
+
+    for (i = 0; i < MAX_PARTITIONS; i++)
+        free(ctx->tokens[i].coeffs);
+
+    free(ctx->above_token_entropy_ctx);
+}
diff --git a/vp8/dixie/tokens.h b/vp8/dixie/tokens.h
index 577f05e052..4ecaba0448 100644
--- a/vp8/dixie/tokens.h
+++ b/vp8/dixie/tokens.h
@@ -14,6 +14,10 @@ void
 vp8_dixie_tokens_init(struct vp8_decoder_ctx *ctx);
 
 
+void
+vp8_dixie_tokens_destroy(struct vp8_decoder_ctx *ctx);
+
+
 void
 vp8_dixie_tokens_process_row(struct vp8_decoder_ctx *ctx,
                              unsigned int            partition,
diff --git a/vp8/vp8_dixie_iface.c b/vp8/vp8_dixie_iface.c
index 5f0c7902c3..f5e1de9ae7 100644
--- a/vp8/vp8_dixie_iface.c
+++ b/vp8/vp8_dixie_iface.c
@@ -82,6 +82,7 @@ static vpx_codec_err_t vp8_init(vpx_codec_ctx_t *ctx)
 
 static vpx_codec_err_t vp8_destroy(vpx_codec_alg_priv_t *ctx)
 {
+    vp8_dixie_decode_destroy(&ctx->decoder_ctx);
     vpx_free(ctx->base.alg_priv);
     return VPX_CODEC_OK;
 }
-- 
GitLab