diff mbox

[FFmpeg-devel,PATCHv2] dashdec: Only free url string if being reused

Message ID 1516410875-17541-1-git-send-email-redmcg@redmandi.dyndns.org
State Accepted
Commit 1f48c5c0671bb4f39c9dc3ec44c727f1680547b3
Headers show

Commit Message

Brendan McGrath Jan. 20, 2018, 1:14 a.m. UTC
If no representation bandwidth value is set, the url value returned
by get_content_url is corrupt (as it has been freed).

This change ensures the url string is not freed unless it is about
to be reused

Signed-off-by: Brendan McGrath <redmcg@redmandi.dyndns.org>
---
Changes since v1:
 - removed the unneeded 'if' statement (as pointed out by Michael Niedermayer
 - added comment to make it clear why the av_free was required

 libavformat/dashdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Liu Steven Jan. 21, 2018, 6:02 a.m. UTC | #1
> 在 2018年1月20日,上午9:14,Brendan McGrath <redmcg@redmandi.dyndns.org> 写道:
> 
> If no representation bandwidth value is set, the url value returned
> by get_content_url is corrupt (as it has been freed).
> 
> This change ensures the url string is not freed unless it is about
> to be reused
> 
> Signed-off-by: Brendan McGrath <redmcg@redmandi.dyndns.org>
> ---
> Changes since v1:
> - removed the unneeded 'if' statement (as pointed out by Michael Niedermayer
> - added comment to make it clear why the av_free was required
> 
> libavformat/dashdec.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
> index 2492f1d..6380318 100644
> --- a/libavformat/dashdec.c
> +++ b/libavformat/dashdec.c
> @@ -482,9 +482,10 @@ static char *get_content_url(xmlNodePtr *baseurl_nodes,
>             return NULL;
>         }
>         av_strlcpy(tmp_str, url, sizeof(tmp_str));
> -        av_free(url);
>     }
>     if (rep_bandwidth_val && tmp_str[0] != '\0') {
> +        // free any previously assigned url before reassigning
> +        av_free(url);
>         url = av_strireplace(tmp_str, "$Bandwidth$", (const char*)rep_bandwidth_val);
>         if (!url) {
>             return NULL;
> -- 
> 2.7.4
> 

pushed

Thanks
Steven
diff mbox

Patch

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index 2492f1d..6380318 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -482,9 +482,10 @@  static char *get_content_url(xmlNodePtr *baseurl_nodes,
             return NULL;
         }
         av_strlcpy(tmp_str, url, sizeof(tmp_str));
-        av_free(url);
     }
     if (rep_bandwidth_val && tmp_str[0] != '\0') {
+        // free any previously assigned url before reassigning
+        av_free(url);
         url = av_strireplace(tmp_str, "$Bandwidth$", (const char*)rep_bandwidth_val);
         if (!url) {
             return NULL;