Skip to content

Commit

Permalink
fixed a memory leak when decoding compressed GPMF streams
Browse files Browse the repository at this point in the history
  • Loading branch information
dnewman-gpsw committed Aug 20, 2020
1 parent 2cfff3c commit 3546834
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
15 changes: 14 additions & 1 deletion GPMF_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
*
Expand Down Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion GPMF_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
*
Expand Down Expand Up @@ -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
Expand Down
13 changes: 3 additions & 10 deletions demo/GPMF_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -186,7 +177,6 @@ int main(int argc, char* argv[])
}
}


if (show_payload_index)
{
if (show_all_payloads || index == 0)
Expand Down Expand Up @@ -375,6 +365,8 @@ int main(int argc, char* argv[])
GPMF_ResetState(ms);
}
}

GPMF_Free(ms);
}

if (show_computed_samplerates)
Expand All @@ -394,6 +386,7 @@ int main(int argc, char* argv[])
}

cleanup:
if (ms) GPMF_Free(ms);
if (payload) FreePayload(payload); payload = NULL;
CloseSource(mp4);
}
Expand Down

0 comments on commit 3546834

Please sign in to comment.