From: Miklos Szeredi Date: Mon, 18 Feb 2013 15:24:11 +0000 (+0100) Subject: fuse_opt_parse(): fix memory leak X-Git-Tag: fuse-3.0.0pre0~132 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=a38722be2ba63466431616a0756981697d29fa23;p=qemu-gpiodev%2Flibfuse.git fuse_opt_parse(): fix memory leak when storing a newly allocated string for format "%s", free the previous value stored at that location. Reported by Marco Schuster --- diff --git a/ChangeLog b/ChangeLog index 502a9bb..9a775bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2013-02-18 Miklos Szeredi + + * fuse_opt_parse(): when storing a newly allocated string for + format "%s", free the previous value stored at that location. + Reported by Marco Schuster + 2013-02-07 Miklos Szeredi * libfuse: add readdirplus support in fuse_lowlevel_ops. Patch by diff --git a/include/fuse_opt.h b/include/fuse_opt.h index add0a30..20653b1 100644 --- a/include/fuse_opt.h +++ b/include/fuse_opt.h @@ -70,8 +70,9 @@ extern "C" { * * 6) "-x %s", etc. Combination of 4) and 5) * - * If the format is "%s", memory is allocated for the string unlike - * with scanf(). + * If the format is "%s", memory is allocated for the string unlike with + * scanf(). The previous value (if non-NULL) stored at the this location is + * freed. */ struct fuse_opt { /** Matching template and optional parameter formatting */ diff --git a/lib/fuse_opt.c b/lib/fuse_opt.c index 93efd29..15f9e21 100644 --- a/lib/fuse_opt.c +++ b/lib/fuse_opt.c @@ -204,11 +204,13 @@ static int process_opt_param(void *var, const char *format, const char *param, { assert(format[0] == '%'); if (format[1] == 's') { + char **s = var; char *copy = strdup(param); if (!copy) return alloc_failed(); - *(char **) var = copy; + free(*s); + *s = copy; } else { if (sscanf(param, format, var) != 1) { fprintf(stderr, "fuse: invalid parameter in option `%s'\n", arg);