[FFmpeg-devel] [PATCH 1/2] ffserver: dont leak child arguments
Lukasz Marek
lukasz.m.luki2 at gmail.com
Fri Nov 21 00:47:18 CET 2014
Signed-off-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
---
ffserver.c | 2 +-
ffserver_config.c | 18 +++++++++++++++++-
ffserver_config.h | 2 ++
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/ffserver.c b/ffserver.c
index 933eb0e..40a5faa 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -3660,7 +3660,7 @@ static void handle_child_exit(int sig)
if (uptime < 30)
/* Turn off any more restarts */
- feed->child_argv = 0;
+ ffserver_free_child_args(&feed->child_argv);
}
}
}
diff --git a/ffserver_config.c b/ffserver_config.c
index 02c8431..a235142 100644
--- a/ffserver_config.c
+++ b/ffserver_config.c
@@ -31,6 +31,8 @@
#include "cmdutils.h"
#include "ffserver_config.h"
+#define MAX_CHILD_ARGS 64
+
static int ffserver_save_avoption(AVCodecContext *ctx, const char *opt, const char *arg,
AVDictionary **dict, int type, FFServerConfig *config, int line_num);
static void vreport_config_error(const char *filename, int line_num, int log_level,
@@ -603,7 +605,7 @@ static int ffserver_parse_config_feed(FFServerConfig *config, const char *cmd, c
if (!av_strcasecmp(cmd, "Launch")) {
int i;
- feed->child_argv = av_mallocz(64 * sizeof(char *));
+ feed->child_argv = av_mallocz_array(MAX_CHILD_ARGS, sizeof(char *));
if (!feed->child_argv)
return AVERROR(ENOMEM);
for (i = 0; i < 62; i++) {
@@ -1278,3 +1280,17 @@ int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config)
#undef ERROR
#undef WARNING
+
+void ffserver_free_child_args(void *argsp)
+{
+ int i;
+ char **args;
+ if (!argsp)
+ return;
+ args = *(char ***)argsp;
+ if (!args)
+ return;
+ for (i = 0; i < MAX_CHILD_ARGS; i++)
+ av_free(args[i]);
+ av_freep(argsp);
+}
diff --git a/ffserver_config.h b/ffserver_config.h
index 06981de..5bc47b4 100644
--- a/ffserver_config.h
+++ b/ffserver_config.h
@@ -127,4 +127,6 @@ void ffserver_parse_acl_row(FFServerStream *stream, FFServerStream* feed,
int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config);
+void ffserver_free_child_args(void *argsp);
+
#endif /* FFSERVER_CONFIG_H */
--
1.9.1
More information about the ffmpeg-devel
mailing list