Skip to content

Commit

Permalink
ffserver: dont leak child arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
  • Loading branch information
Lukasz Marek committed Nov 26, 2014
1 parent ec6e035 commit 3cb0bec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ffserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -3663,7 +3663,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);
}
}
}
Expand Down
20 changes: 18 additions & 2 deletions ffserver_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "cmdutils.h"
#include "ffserver_config.h"

#define MAX_CHILD_ARGS 64

static int ffserver_save_avoption(const char *opt, const char *arg, int type,
FFServerConfig *config);
static void vreport_config_error(const char *filename, int line_num, int log_level,
Expand Down Expand Up @@ -691,10 +693,10 @@ 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++) {
for (i = 0; i < MAX_CHILD_ARGS - 2; i++) {
ffserver_get_arg(arg, sizeof(arg), p);
if (!arg[0])
break;
Expand Down Expand Up @@ -1255,3 +1257,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);
}
2 changes: 2 additions & 0 deletions ffserver_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,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 */

0 comments on commit 3cb0bec

Please sign in to comment.