[pve-devel] [PATCH cluster] Fix #1383: pmxcfs: use memdb_tree_entry_free()

Wolfgang Bumiller w.bumiller at proxmox.com
Tue May 16 11:32:41 CEST 2017


Use the right destructor instead of g_free(), as it may
contain another data pointer which needs freeing.
---
The leak is the part in dcdb.c, where the entry isn't freed at all.
The rest is mostly for consistency (even though some of them allocate
the entry manually with g_malloc0 and fill it manually (which I don't
like btw., especially because it also makes adding valgrind macros to
catch mismatching new/delete pairs a hassle.)), but note that the second
hunk uses memdb_getattr(), iow. the structure isn't filled manually and
may contain data pointers, so g_free() is definitely wrong there.

 data/src/cfs-plug-memdb.c | 7 +++----
 data/src/dcdb.c           | 1 +
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/data/src/cfs-plug-memdb.c b/data/src/cfs-plug-memdb.c
index c0619f9..cc12874 100644
--- a/data/src/cfs-plug-memdb.c
+++ b/data/src/cfs-plug-memdb.c
@@ -129,7 +129,7 @@ static int cfs_plug_memdb_getattr(cfs_plug_t *plug, const char *path, struct sta
 
 	if (te) {
 		tree_entry_stat(te, stbuf, cfs_is_quorate());
-		g_free(te);
+		memdb_tree_entry_free(te);
 		return 0;
 	}
 
@@ -192,7 +192,7 @@ static int cfs_plug_memdb_open(cfs_plug_t *plug, const char *path, struct fuse_f
 	cfs_plug_memdb_t *mdb = (cfs_plug_memdb_t *)plug;
 
 	if ((te = memdb_getattr(mdb->memdb, path))) {
-		g_free(te);
+		memdb_tree_entry_free(te);
 	} else 
 		return -ENOENT;
 
@@ -443,8 +443,7 @@ static int cfs_plug_memdb_utimens(
 		}
 	}
 
-	if (te)
-		g_free(te);
+	memdb_tree_entry_free(te);
 
 	return res;
 }
diff --git a/data/src/dcdb.c b/data/src/dcdb.c
index 4e7859f..2818845 100644
--- a/data/src/dcdb.c
+++ b/data/src/dcdb.c
@@ -846,6 +846,7 @@ dcdb_deliver(
 				}
 			}
 		}
+		memdb_tree_entry_free(te);
 
 	} else if (msg_type == DCDB_MESSAGE_CFS_WRITE) {
 
-- 
2.11.0





More information about the pve-devel mailing list