Commit 09afddf0 authored by Limin Wang's avatar Limin Wang Committed by Steven Liu

avformat/hlsenc: free the original malloc pointer to avoid error when system...

avformat/hlsenc: free the original malloc pointer to avoid error when system function used in the following patch
Signed-off-by: 's avatarLimin Wang <lance.lmwang@gmail.com>
parent 4e0860e3
...@@ -493,8 +493,11 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls, ...@@ -493,8 +493,11 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
int ret = 0, path_size, sub_path_size; int ret = 0, path_size, sub_path_size;
int segment_cnt = 0; int segment_cnt = 0;
char *dirname = NULL, *sub_path; char *dirname = NULL, *sub_path;
char *dirname_r = NULL;
char *dirname_repl = NULL;
char *path = NULL; char *path = NULL;
char *vtt_dirname = NULL; char *vtt_dirname = NULL;
char *vtt_dirname_r = NULL;
AVDictionary *options = NULL; AVDictionary *options = NULL;
AVIOContext *out = NULL; AVIOContext *out = NULL;
const char *proto = NULL; const char *proto = NULL;
...@@ -523,28 +526,27 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls, ...@@ -523,28 +526,27 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
} }
if (segment && !hls->use_localtime_mkdir) { if (segment && !hls->use_localtime_mkdir) {
char *dirname_r = hls->segment_filename ? av_strdup(hls->segment_filename): av_strdup(vs->avf->url); dirname_r = hls->segment_filename ? av_strdup(hls->segment_filename): av_strdup(vs->avf->url);
dirname = (char*)av_dirname(dirname_r); dirname = (char*)av_dirname(dirname_r);
} }
/* if %v is present in the file's directory /* if %v is present in the file's directory
* all segment belongs to the same variant, so do it only once before the loop*/ * all segment belongs to the same variant, so do it only once before the loop*/
if (dirname && av_stristr(dirname, "%v")) { if (dirname && av_stristr(dirname, "%v")) {
char * r_dirname = dirname; char * dirname_repl = dirname;
if (!vs->varname) { if (!vs->varname) {
if (replace_int_data_in_filename(&r_dirname, dirname, 'v', segment->var_stream_idx) < 1) { if (replace_int_data_in_filename(&dirname_repl, dirname, 'v', segment->var_stream_idx) < 1) {
ret = AVERROR(EINVAL); ret = AVERROR(EINVAL);
goto fail; goto fail;
} }
} else { } else {
if (replace_str_data_in_filename(&r_dirname, dirname, 'v', vs->varname) < 1) { if (replace_str_data_in_filename(&dirname_repl, dirname, 'v', vs->varname) < 1) {
ret = AVERROR(EINVAL); ret = AVERROR(EINVAL);
goto fail; goto fail;
} }
} }
av_freep(&dirname); dirname = dirname_repl;
dirname = r_dirname;
} }
while (segment) { while (segment) {
...@@ -578,7 +580,7 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls, ...@@ -578,7 +580,7 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
} }
if ((segment->sub_filename[0] != '\0')) { if ((segment->sub_filename[0] != '\0')) {
char *vtt_dirname_r = av_strdup(vs->vtt_avf->url); vtt_dirname_r = av_strdup(vs->vtt_avf->url);
vtt_dirname = (char*)av_dirname(vtt_dirname_r); vtt_dirname = (char*)av_dirname(vtt_dirname_r);
sub_path_size = strlen(segment->sub_filename) + 1 + strlen(vtt_dirname) + 1; sub_path_size = strlen(segment->sub_filename) + 1 + strlen(vtt_dirname) + 1;
sub_path = av_malloc(sub_path_size); sub_path = av_malloc(sub_path_size);
...@@ -589,7 +591,7 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls, ...@@ -589,7 +591,7 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
snprintf(sub_path, sub_path_size, "%s%c%s", vtt_dirname, SEPARATOR, segment->sub_filename); snprintf(sub_path, sub_path_size, "%s%c%s", vtt_dirname, SEPARATOR, segment->sub_filename);
av_freep(&vtt_dirname); av_freep(&vtt_dirname_r);
if (hls->method || (proto && !av_strcasecmp(proto, "http"))) { if (hls->method || (proto && !av_strcasecmp(proto, "http"))) {
av_dict_set(&options, "method", "DELETE", 0); av_dict_set(&options, "method", "DELETE", 0);
...@@ -614,8 +616,9 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls, ...@@ -614,8 +616,9 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
fail: fail:
av_freep(&path); av_freep(&path);
av_freep(&dirname); av_freep(&dirname_r);
av_freep(&vtt_dirname); av_freep(&dirname_repl);
av_freep(&vtt_dirname_r);
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment