mirror of
https://github.com/libfuse/libfuse.git
synced 2024-11-27 06:04:27 +08:00
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
This commit is contained in:
parent
4337a32955
commit
a38722be2b
@ -1,3 +1,9 @@
|
||||
2013-02-18 Miklos Szeredi <miklos@szeredi.hu>
|
||||
|
||||
* 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 <miklos@szeredi.hu>
|
||||
|
||||
* libfuse: add readdirplus support in fuse_lowlevel_ops. Patch by
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user