diff mbox

[FFmpeg-devel] webmdashenc: Fix memory leak

Message ID 20170714143800.9231-1-derek.buitenhuis@gmail.com
State Accepted
Commit a27c412795c2147e71c5b10782c97a15bf9dc81f
Headers show

Commit Message

Derek Buitenhuis July 14, 2017, 2:38 p.m. UTC
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
---
 libavformat/webmdashenc.c | 38 ++++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)

Comments

Derek Buitenhuis July 16, 2017, 12:45 p.m. UTC | #1
On 7/14/2017 3:38 PM, Derek Buitenhuis wrote:
> Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
> ---
>  libavformat/webmdashenc.c | 38 ++++++++++++++++++++++++++++++--------
>  1 file changed, 30 insertions(+), 8 deletions(-)

Pushing today, unless there are objections.

- Derek
Ronald S. Bultje July 16, 2017, 5:41 p.m. UTC | #2
Hi,

On Sun, Jul 16, 2017 at 8:45 AM, Derek Buitenhuis <
derek.buitenhuis@gmail.com> wrote:

> On 7/14/2017 3:38 PM, Derek Buitenhuis wrote:
> > Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
> > ---
> >  libavformat/webmdashenc.c | 38 ++++++++++++++++++++++++++++++--------
> >  1 file changed, 30 insertions(+), 8 deletions(-)
>
> Pushing today, unless there are objections.


No objections & LGTM.

Ronald
diff mbox

Patch

diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
index 550ad72e4d..1280d8a763 100644
--- a/libavformat/webmdashenc.c
+++ b/libavformat/webmdashenc.c
@@ -288,33 +288,55 @@  static int parse_filename(char *filename, char **representation_id,
     char *period_pos = NULL;
     char *temp_pos = NULL;
     char *filename_str = av_strdup(filename);
-    if (!filename_str) return AVERROR(ENOMEM);
+    int ret = 0;
+
+    if (!filename_str) {
+        ret = AVERROR(ENOMEM);
+        goto end;
+    }
     temp_pos = av_stristr(filename_str, "_");
     while (temp_pos) {
         underscore_pos = temp_pos + 1;
         temp_pos = av_stristr(temp_pos + 1, "_");
     }
-    if (!underscore_pos) return AVERROR_INVALIDDATA;
+    if (!underscore_pos) {
+        ret = AVERROR_INVALIDDATA;
+        goto end;
+    }
     period_pos = av_stristr(underscore_pos, ".");
-    if (!period_pos) return AVERROR_INVALIDDATA;
+    if (!period_pos) {
+        ret = AVERROR_INVALIDDATA;
+        goto end;
+    }
     *(underscore_pos - 1) = 0;
     if (representation_id) {
         *representation_id = av_malloc(period_pos - underscore_pos + 1);
-        if (!(*representation_id)) return AVERROR(ENOMEM);
+        if (!(*representation_id)) {
+            ret = AVERROR(ENOMEM);
+            goto end;
+        }
         av_strlcpy(*representation_id, underscore_pos, period_pos - underscore_pos + 1);
     }
     if (initialization_pattern) {
         *initialization_pattern = av_asprintf("%s_$RepresentationID$.hdr",
                                               filename_str);
-        if (!(*initialization_pattern)) return AVERROR(ENOMEM);
+        if (!(*initialization_pattern)) {
+            ret = AVERROR(ENOMEM);
+            goto end;
+        }
     }
     if (media_pattern) {
         *media_pattern = av_asprintf("%s_$RepresentationID$_$Number$.chk",
                                      filename_str);
-        if (!(*media_pattern)) return AVERROR(ENOMEM);
+        if (!(*media_pattern)) {
+            ret = AVERROR(ENOMEM);
+            goto end;
+        }
     }
-    av_free(filename_str);
-    return 0;
+
+end:
+    av_freep(&filename_str);
+    return ret;
 }
 
 /*