[FFmpeg-devel] [PATCH v1] libavfilter/af_channelsplit.c:fix memory leak

2024-04-12 Thread LuMingYin
Signed-off-by: LuMingYin 
---
 libavfilter/af_channelsplit.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavfilter/af_channelsplit.c b/libavfilter/af_channelsplit.c
index d18d91dcb6..2cfac19cd3 100644
--- a/libavfilter/af_channelsplit.c
+++ b/libavfilter/af_channelsplit.c
@@ -163,8 +163,10 @@ static int filter_frame(AVFilterLink *outlink, AVFrame 
*buf)
 
 buf_out->data[0] = buf_out->extended_data[0] = 
buf_out->extended_data[s->map[i]];
 ret = av_channel_layout_from_mask(&buf_out->ch_layout, 1ULL << channel);
-if (ret < 0)
+if (ret < 0){
+av_frame_free(&buf_out);
 return ret;
+}
 
 return ff_filter_frame(ctx->outputs[i], buf_out);
 }
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] fftools/ffmpeg_demux: fix memory leak on error path

2024-04-12 Thread LuMingYin
In the file ffmpeg_demux.c located at /FFmpeg/fftools/, a pointer variable 
named ic is defined at line 1531. At line 1589, the program allocates a dynamic 
memory area for it using the function avformat_alloc_context. When the if 
statement at line 1668 evaluates to true, the function returns at line 1673. 
Throughout this process, the dynamic memory area pointed to by the ic pointer 
is not deallocated, resulting in a memory leak.

Signed-off-by: LuMingYin 
---
 fftools/ffmpeg_demux.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index cba63dab5f..2cfcc3c69d 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1670,6 +1670,7 @@ int ifile_open(const OptionsContext *o, const char 
*filename, Scheduler *sch)
"Error opening input: %s\n", av_err2str(err));
 if (err == AVERROR_PROTOCOL_NOT_FOUND)
 av_log(d, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
+avformat_free_context(ic);
 return err;
 }
 f->ctx = ic;
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] fftools/ffmpeg_mux_init: fix a memory leak in ffmpeg_mux_init.c

2024-04-12 Thread LuMingYin
In the file ffmpeg_mux_init.c located at /FFmpeg/fftools/, a pointer variable 
named pts is defined at line 2830. At line 2836, this pointer is allocated a 
dynamic memory area using the function av_malloc_array. When the if statement 
at line 2852 evaluates to true, there are two possible scenarios. The first 
scenario is when nb_ch > INT_MAX - size. In this case, the program should 
release the dynamic memory area pointed to by pts before returning. The second 
scenario is when the realloc operation for the pts pointer fails. In this case, 
since the av_realloc_f function releases the original memory in case of 
reallocation failure, there is no need to release the memory area pointed to by 
pts. Because the handling of these two scenarios differs, to fix the memory 
leak issue caused by the first scenario, my patch separates the treatment of 
these cases.

Signed-off-by: LuMingYin 
---
 fftools/ffmpeg_mux_init.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 6d8bd5bcdf..1f27e4e4f4 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -2849,8 +2849,12 @@ static int parse_forced_key_frames(void *log, 
KeyframeForceCtx *kf,
 unsigned intnb_ch = mux->fc->nb_chapters;
 int j;
 
-if (nb_ch > INT_MAX - size ||
-!(pts = av_realloc_f(pts, size += nb_ch - 1,
+if (nb_ch > INT_MAX - size) {
+av_freep(&pts);
+return AVERROR(ENOMEM);
+}
+
+if (!(pts = av_realloc_f(pts, size += nb_ch - 1,
  sizeof(*pts
 return AVERROR(ENOMEM);
 
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] fftools/ffmpeg_mux_init: fix memory leak in ffmpeg_mux_init.c

2024-04-12 Thread LuMingYin
Signed-off-by: LuMingYin 
---
 fftools/ffmpeg_mux_init.c | 7 ---
 libavutil/mem.c   | 5 -
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 6d8bd5bcdf..e7e2281bd0 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -2851,9 +2851,10 @@ static int parse_forced_key_frames(void *log, 
KeyframeForceCtx *kf,
 
 if (nb_ch > INT_MAX - size ||
 !(pts = av_realloc_f(pts, size += nb_ch - 1,
- sizeof(*pts
-return AVERROR(ENOMEM);
-
+ sizeof(*pts {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
 if (p[8]) {
 ret = av_parse_time(&t, p + 8, 1);
 if (ret < 0) {
diff --git a/libavutil/mem.c b/libavutil/mem.c
index b205d3fb25..7f34765fe7 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -177,11 +177,14 @@ void *av_realloc_f(void *ptr, size_t nelem, size_t elsize)
 
 if (size_mult(elsize, nelem, &size)) {
 av_free(ptr);
+ptr = NULL;
 return NULL;
 }
 r = av_realloc(ptr, size);
-if (!r)
+if (!r) {
 av_free(ptr);
+ptr = NULL;
+}
 return r;
 }
 
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] fftools/ffmpeg_mux_init: fix a memory leak in ffmpeg_mux_init.c

2024-04-12 Thread LuMingYin
Signed-off-by: LuMingYin 
---
 fftools/ffmpeg_mux_init.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 6d8bd5bcdf..d2146cef8c 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -2851,8 +2851,10 @@ static int parse_forced_key_frames(void *log, 
KeyframeForceCtx *kf,
 
 if (nb_ch > INT_MAX - size ||
 !(pts = av_realloc_f(pts, size += nb_ch - 1,
- sizeof(*pts
-return AVERROR(ENOMEM);
+ sizeof(*pts {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
 
 if (p[8]) {
 ret = av_parse_time(&t, p + 8, 1);
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavfilter/vf_curves: fix a memory leak in libavfilter/vf_curves.c

2024-04-12 Thread LuMingYin
The pointer variable 'point', which is defined and dynamically allocated memory 
within the while loop of the 'parse_points_str' function, is not released on 
error paths.

Signed-off-by: LuMingYin 
---
 libavfilter/vf_curves.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_curves.c b/libavfilter/vf_curves.c
index 3e4a42bab3..97f284db22 100644
--- a/libavfilter/vf_curves.c
+++ b/libavfilter/vf_curves.c
@@ -182,20 +182,22 @@ static int parse_points_str(AVFilterContext *ctx, struct 
keypoint **points, cons
 if (point->x < 0 || point->x > 1 || point->y < 0 || point->y > 1) {
 av_log(ctx, AV_LOG_ERROR, "Invalid key point coordinates (%f;%f), "
"x and y must be in the [0;1] range.\n", point->x, 
point->y);
+av_free(point);
 return AVERROR(EINVAL);
 }
-if (!*points)
-*points = point;
 if (last) {
 if ((int)(last->x * scale) >= (int)(point->x * scale)) {
 av_log(ctx, AV_LOG_ERROR, "Key point coordinates (%f;%f) "
"and (%f;%f) are too close from each other or not "
"strictly increasing on the x-axis\n",
last->x, last->y, point->x, point->y);
+av_free(point);
 return AVERROR(EINVAL);
 }
 last->next = point;
 }
+if (!*points)
+*points = point;
 last = point;
 }
 
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavformat/rtsp: fix a memory leak in libavformat/rtsp.c

2024-04-12 Thread LuMingYin
The pointer variable 'fds' allocates a block of dynamic memory in the function 
'ffurl_get_multi_file_handle', and the dynamic memory pointed to by this 
pointer is not released on error paths.

Signed-off-by: LuMingYin 
---
 libavformat/rtsp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index b0c61ee00a..db78735c7a 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -2071,6 +2071,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream 
**prtsp_st,
 if (fdsnum != 2) {
 av_log(s, AV_LOG_ERROR,
"Number of fds %d not supported\n", fdsnum);
+av_freep(&fds);
 return AVERROR_INVALIDDATA;
 }
 for (fdsidx = 0; fdsidx < fdsnum; fdsidx++) {
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] libavformat/hlsenc: fix a memory leak in libavformat/hlsenc.c

2024-04-12 Thread LuMingYin
In the function 'hls_write_trailer' in the file '/FFmpeg/libavformat/hlsenc.c', 
the variable named 'options' allocates a block of dynamic memory in the 
'av_dict_set' function, which is not freed on error paths.

Signed-off-by: LuMingYin 
---
 libavformat/hlsenc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index bde7230036..0e2843c6bc 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2757,6 +2757,7 @@ static int hls_write_trailer(struct AVFormatContext *s)
 filename = av_asprintf("%s", oc->url);
 }
 if (!filename) {
+av_dict_free(&options);
 av_freep(&old_filename);
 return AVERROR(ENOMEM);
 }
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".