54 lines
1.7 KiB
Diff
54 lines
1.7 KiB
Diff
From a38722be2ba63466431616a0756981697d29fa23 Mon Sep 17 00:00:00 2001
|
|
From: Miklos Szeredi <mszeredi@suse.cz>
|
|
Date: Mon, 18 Feb 2013 16:24:11 +0100
|
|
Subject: [PATCH 032/617] 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
|
|
---
|
|
ChangeLog | 6 ++++++
|
|
include/fuse_opt.h | 5 +++--
|
|
lib/fuse_opt.c | 4 +++-
|
|
3 files changed, 12 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/libfuse-fuse-2.9.7/include/fuse_opt.h b/libfuse-fuse-2.9.7/include/fuse_opt.h
|
|
index add0a30..20653b1 100644
|
|
--- a/libfuse-fuse-2.9.7/include/fuse_opt.h
|
|
+++ b/libfuse-fuse-2.9.7/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/libfuse-fuse-2.9.7/lib/fuse_opt.c b/libfuse-fuse-2.9.7/lib/fuse_opt.c
|
|
index 93efd29..15f9e21 100644
|
|
--- a/libfuse-fuse-2.9.7/lib/fuse_opt.c
|
|
+++ b/libfuse-fuse-2.9.7/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);
|
|
--
|
|
1.8.3.1
|
|
|