From 35468344fca7a4005c2d45a0abfda77120efcd9d Mon Sep 17 00:00:00 2001 From: dnewman-gpsw Date: Thu, 20 Aug 2020 09:58:41 -0700 Subject: [PATCH] fixed a memory leak when decoding compressed GPMF streams --- GPMF_parser.c | 15 ++++++++++++++- GPMF_parser.h | 3 ++- demo/GPMF_demo.c | 13 +++---------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/GPMF_parser.c b/GPMF_parser.c index f909a6a..5c004ca 100644 --- a/GPMF_parser.c +++ b/GPMF_parser.c @@ -2,7 +2,7 @@ * * @brief GPMF Parser library * - * @version 1.7.0 + * @version 2.0.0 * * (C) Copyright 2017-2020 GoPro Inc (http://gopro.com/). * @@ -2139,3 +2139,16 @@ GPMF_ERR GPMF_FreeCodebook(size_t cbhandle) return GPMF_ERROR_MEMORY; } +GPMF_ERR GPMF_Free(GPMF_stream* ms) +{ + if (ms) + { + if (ms->cbhandle != 0) + { + GPMF_FreeCodebook(ms->cbhandle); + ms->cbhandle = 0; + } + return GPMF_OK; + } + return GPMF_ERROR_MEMORY; +} \ No newline at end of file diff --git a/GPMF_parser.h b/GPMF_parser.h index e4874ff..582bf85 100644 --- a/GPMF_parser.h +++ b/GPMF_parser.h @@ -2,7 +2,7 @@ * * @brief GPMF Parser library include * - * @version 1.6.1 + * @version 2.0.0 * * (C) Copyright 2017-2020 GoPro Inc (http://gopro.com/). * @@ -116,6 +116,7 @@ GPMF_ERR GPMF_AllocCodebook(size_t *cbhandle); GPMF_ERR GPMF_FreeCodebook(size_t cbhandle); GPMF_ERR GPMF_DecompressedSize(GPMF_stream *gs, uint32_t *neededsize); GPMF_ERR GPMF_Decompress(GPMF_stream *gs, uint32_t *localbuf, uint32_t localbuf_size); +GPMF_ERR GPMF_Free(GPMF_stream* gs); #ifdef __cplusplus diff --git a/demo/GPMF_demo.c b/demo/GPMF_demo.c index 56431ad..8c75fd0 100644 --- a/demo/GPMF_demo.c +++ b/demo/GPMF_demo.c @@ -159,15 +159,6 @@ int main(int argc, char* argv[]) if (show_all_payloads || index == 0) { printf("GPMF STRUCTURE:\n"); - payloadsize = GetPayloadSize(mp4, 0); - payload = GetPayload(mp4, payload, 0); - if (payload == NULL) - goto cleanup; - - ret = GPMF_Init(ms, payload, payloadsize); - if (ret != GPMF_OK) - goto cleanup; - // Output (printf) all the contained GPMF data within this payload ret = GPMF_Validate(ms, GPMF_RECURSE_LEVELS); // optional if (GPMF_OK != ret) @@ -186,7 +177,6 @@ int main(int argc, char* argv[]) } } - if (show_payload_index) { if (show_all_payloads || index == 0) @@ -375,6 +365,8 @@ int main(int argc, char* argv[]) GPMF_ResetState(ms); } } + + GPMF_Free(ms); } if (show_computed_samplerates) @@ -394,6 +386,7 @@ int main(int argc, char* argv[]) } cleanup: + if (ms) GPMF_Free(ms); if (payload) FreePayload(payload); payload = NULL; CloseSource(mp4); }