[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 2/2] storage: make previous leak less likely to regress



Splitting into two functions allows the user to call the right
function, rather than having to remember that a *Free function is
an exception to the rule.

* src/conf/storage_conf.h (virStoragePoolSourceClear): New function.
* src/libvirt_private.syms (storage_conf.h): Export it.
* src/conf/storage_conf.c (virStoragePoolSourceFree): Split...
(virStoragePoolSourceClear): ...into new function.
(virStoragePoolDefFree, virStoragePoolDefParseSourceString):
Update callers.
* src/test/test_driver.c (testStorageFindPoolSources): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSourcesFunc)
(virStorageBackendFileSystemNetFindPoolSources): Likewise.
* src/storage/storage_backend_iscsi.c
(virStorageBackendISCSIFindPoolSources): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalFindPoolSources): Likewise.
---
 src/conf/storage_conf.c               |   13 ++++++++++---
 src/conf/storage_conf.h               |    3 ++-
 src/libvirt_private.syms              |    5 +++--
 src/storage/storage_backend_fs.c      |    7 ++-----
 src/storage/storage_backend_iscsi.c   |    1 -
 src/storage/storage_backend_logical.c |    3 +--
 src/test/test_driver.c                |    1 -
 7 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index e893b2d..4f4f5ce 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -269,7 +269,8 @@ virStorageVolDefFree(virStorageVolDefPtr def) {
 }

 void
-virStoragePoolSourceFree(virStoragePoolSourcePtr source) {
+virStoragePoolSourceClear(virStoragePoolSourcePtr source)
+{
     int i;

     if (!source)
@@ -295,13 +296,20 @@ virStoragePoolSourceFree(virStoragePoolSourcePtr source) {
 }

 void
+virStoragePoolSourceFree(virStoragePoolSourcePtr source)
+{
+    virStoragePoolSourceClear(source);
+    VIR_FREE(source);
+}
+
+void
 virStoragePoolDefFree(virStoragePoolDefPtr def) {
     if (!def)
         return;

     VIR_FREE(def->name);

-    virStoragePoolSourceFree(&def->source);
+    virStoragePoolSourceClear(&def->source);

     VIR_FREE(def->target.path);
     VIR_FREE(def->target.perms.label);
@@ -529,7 +537,6 @@ virStoragePoolDefParseSourceString(const char *srcSpec,
     def = NULL;
 cleanup:
     virStoragePoolSourceFree(def);
-    VIR_FREE(def);
     xmlFreeDoc(doc);
     xmlXPathFreeContext(xpath_ctxt);

diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index d115a15..19bbd2c 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -1,7 +1,7 @@
 /*
  * storage_conf.h: config handling for storage driver
  *
- * Copyright (C) 2006-2008, 2010 Red Hat, Inc.
+ * Copyright (C) 2006-2008, 2010-2011 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -372,6 +372,7 @@ int virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
 int virStoragePoolObjDeleteDef(virStoragePoolObjPtr pool);

 void virStorageVolDefFree(virStorageVolDefPtr def);
+void virStoragePoolSourceClear(virStoragePoolSourcePtr source);
 void virStoragePoolSourceFree(virStoragePoolSourcePtr source);
 void virStoragePoolDefFree(virStoragePoolDefPtr def);
 void virStoragePoolObjFree(virStoragePoolObjPtr pool);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8a6e8d3..4ae1157 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -992,14 +992,15 @@ virStoragePoolObjClearVols;
 virStoragePoolObjDeleteDef;
 virStoragePoolObjFindByName;
 virStoragePoolObjFindByUUID;
-virStoragePoolSourceFindDuplicateDevices;
 virStoragePoolObjIsDuplicate;
-virStoragePoolSourceFindDuplicate;
 virStoragePoolObjListFree;
 virStoragePoolObjLock;
 virStoragePoolObjRemove;
 virStoragePoolObjSaveDef;
 virStoragePoolObjUnlock;
+virStoragePoolSourceClear;
+virStoragePoolSourceFindDuplicate;
+virStoragePoolSourceFindDuplicateDevices;
 virStoragePoolSourceFree;
 virStoragePoolSourceListFormat;
 virStoragePoolSourceListNewSource;
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index d678625..3473435 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -217,7 +217,6 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTR
     ret = 0;
 cleanup:
     virStoragePoolSourceFree(src);
-    VIR_FREE(src);
     return ret;
 }

@@ -277,12 +276,10 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE

  cleanup:
     for (i = 0; i < state.list.nsources; i++)
-        virStoragePoolSourceFree(&state.list.sources[i]);
+        virStoragePoolSourceClear(&state.list.sources[i]);
+    VIR_FREE(state.list.sources);

     virStoragePoolSourceFree(source);
-    VIR_FREE(source);
-
-    VIR_FREE(state.list.sources);

     return retval;
 }
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index c6e782d..99e69c9 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -611,7 +611,6 @@ cleanup:
     VIR_FREE(targets);
     VIR_FREE(portal);
     virStoragePoolSourceFree(source);
-    VIR_FREE(source);
     return ret;
 }

diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index 50d0407..3c3e736 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -430,8 +430,7 @@ virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,

  cleanup:
     for (i = 0; i < sourceList.nsources; i++)
-        virStoragePoolSourceFree(&sourceList.sources[i]);
-
+        virStoragePoolSourceClear(&sourceList.sources[i]);
     VIR_FREE(sourceList.sources);

     return retval;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index b3e24b4..326409d 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -4088,7 +4088,6 @@ testStorageFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,

 cleanup:
     virStoragePoolSourceFree(source);
-    VIR_FREE(source);
     return ret;
 }

-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]