libopencv: Check kernel_str life cycle

The string might or might not be set depending if there
are args and in case of error it must be freed nonetheless.

CC: libav-stable@libav.org
Bug-Id: CID 739878 / CID 739882
This commit is contained in:
Luca Barbato 2015-02-01 02:02:05 +01:00 committed by Vittorio Giovara
parent 9b8c8a9395
commit a6653787a4
1 changed files with 12 additions and 6 deletions

View File

@ -261,19 +261,25 @@ static av_cold int dilate_init(AVFilterContext *ctx, const char *args)
OCVContext *s = ctx->priv;
DilateContext *dilate = s->priv;
char default_kernel_str[] = "3x3+0x0/rect";
char *kernel_str;
char *kernel_str = NULL;
const char *buf = args;
int ret;
dilate->nb_iterations = 1;
if (args)
if (args) {
kernel_str = av_get_token(&buf, "|");
if ((ret = parse_iplconvkernel(&dilate->kernel,
*kernel_str ? kernel_str : default_kernel_str,
ctx)) < 0)
return ret;
if (!kernel_str)
return AVERROR(ENOMEM);
}
ret = parse_iplconvkernel(&dilate->kernel,
(!kernel_str || !*kernel_str) ? default_kernel_str
: kernel_str,
ctx);
av_free(kernel_str);
if (ret < 0)
return ret;
sscanf(buf, "|%d", &dilate->nb_iterations);
av_log(ctx, AV_LOG_VERBOSE, "iterations_nb:%d\n", dilate->nb_iterations);