mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
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.
This commit is contained in:
parent
79052a76b5
commit
b1836a254e
@ -269,7 +269,8 @@ virStorageVolDefFree(virStorageVolDefPtr def) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
virStoragePoolSourceFree(virStoragePoolSourcePtr source) {
|
virStoragePoolSourceClear(virStoragePoolSourcePtr source)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!source)
|
if (!source)
|
||||||
@ -294,6 +295,13 @@ virStoragePoolSourceFree(virStoragePoolSourcePtr source) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
virStoragePoolSourceFree(virStoragePoolSourcePtr source)
|
||||||
|
{
|
||||||
|
virStoragePoolSourceClear(source);
|
||||||
|
VIR_FREE(source);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
virStoragePoolDefFree(virStoragePoolDefPtr def) {
|
virStoragePoolDefFree(virStoragePoolDefPtr def) {
|
||||||
if (!def)
|
if (!def)
|
||||||
@ -301,7 +309,7 @@ virStoragePoolDefFree(virStoragePoolDefPtr def) {
|
|||||||
|
|
||||||
VIR_FREE(def->name);
|
VIR_FREE(def->name);
|
||||||
|
|
||||||
virStoragePoolSourceFree(&def->source);
|
virStoragePoolSourceClear(&def->source);
|
||||||
|
|
||||||
VIR_FREE(def->target.path);
|
VIR_FREE(def->target.path);
|
||||||
VIR_FREE(def->target.perms.label);
|
VIR_FREE(def->target.perms.label);
|
||||||
@ -529,7 +537,6 @@ virStoragePoolDefParseSourceString(const char *srcSpec,
|
|||||||
def = NULL;
|
def = NULL;
|
||||||
cleanup:
|
cleanup:
|
||||||
virStoragePoolSourceFree(def);
|
virStoragePoolSourceFree(def);
|
||||||
VIR_FREE(def);
|
|
||||||
xmlFreeDoc(doc);
|
xmlFreeDoc(doc);
|
||||||
xmlXPathFreeContext(xpath_ctxt);
|
xmlXPathFreeContext(xpath_ctxt);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* storage_conf.h: config handling for storage driver
|
* 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
|
* Copyright (C) 2006-2008 Daniel P. Berrange
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
@ -372,6 +372,7 @@ int virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
|
|||||||
int virStoragePoolObjDeleteDef(virStoragePoolObjPtr pool);
|
int virStoragePoolObjDeleteDef(virStoragePoolObjPtr pool);
|
||||||
|
|
||||||
void virStorageVolDefFree(virStorageVolDefPtr def);
|
void virStorageVolDefFree(virStorageVolDefPtr def);
|
||||||
|
void virStoragePoolSourceClear(virStoragePoolSourcePtr source);
|
||||||
void virStoragePoolSourceFree(virStoragePoolSourcePtr source);
|
void virStoragePoolSourceFree(virStoragePoolSourcePtr source);
|
||||||
void virStoragePoolDefFree(virStoragePoolDefPtr def);
|
void virStoragePoolDefFree(virStoragePoolDefPtr def);
|
||||||
void virStoragePoolObjFree(virStoragePoolObjPtr pool);
|
void virStoragePoolObjFree(virStoragePoolObjPtr pool);
|
||||||
|
@ -992,14 +992,15 @@ virStoragePoolObjClearVols;
|
|||||||
virStoragePoolObjDeleteDef;
|
virStoragePoolObjDeleteDef;
|
||||||
virStoragePoolObjFindByName;
|
virStoragePoolObjFindByName;
|
||||||
virStoragePoolObjFindByUUID;
|
virStoragePoolObjFindByUUID;
|
||||||
virStoragePoolSourceFindDuplicateDevices;
|
|
||||||
virStoragePoolObjIsDuplicate;
|
virStoragePoolObjIsDuplicate;
|
||||||
virStoragePoolSourceFindDuplicate;
|
|
||||||
virStoragePoolObjListFree;
|
virStoragePoolObjListFree;
|
||||||
virStoragePoolObjLock;
|
virStoragePoolObjLock;
|
||||||
virStoragePoolObjRemove;
|
virStoragePoolObjRemove;
|
||||||
virStoragePoolObjSaveDef;
|
virStoragePoolObjSaveDef;
|
||||||
virStoragePoolObjUnlock;
|
virStoragePoolObjUnlock;
|
||||||
|
virStoragePoolSourceClear;
|
||||||
|
virStoragePoolSourceFindDuplicate;
|
||||||
|
virStoragePoolSourceFindDuplicateDevices;
|
||||||
virStoragePoolSourceFree;
|
virStoragePoolSourceFree;
|
||||||
virStoragePoolSourceListFormat;
|
virStoragePoolSourceListFormat;
|
||||||
virStoragePoolSourceListNewSource;
|
virStoragePoolSourceListNewSource;
|
||||||
|
@ -217,7 +217,6 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTR
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virStoragePoolSourceFree(src);
|
virStoragePoolSourceFree(src);
|
||||||
VIR_FREE(src);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,12 +276,10 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
for (i = 0; i < state.list.nsources; i++)
|
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);
|
virStoragePoolSourceFree(source);
|
||||||
VIR_FREE(source);
|
|
||||||
|
|
||||||
VIR_FREE(state.list.sources);
|
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -611,7 +611,6 @@ cleanup:
|
|||||||
VIR_FREE(targets);
|
VIR_FREE(targets);
|
||||||
VIR_FREE(portal);
|
VIR_FREE(portal);
|
||||||
virStoragePoolSourceFree(source);
|
virStoragePoolSourceFree(source);
|
||||||
VIR_FREE(source);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,8 +430,7 @@ virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
for (i = 0; i < sourceList.nsources; i++)
|
for (i = 0; i < sourceList.nsources; i++)
|
||||||
virStoragePoolSourceFree(&sourceList.sources[i]);
|
virStoragePoolSourceClear(&sourceList.sources[i]);
|
||||||
|
|
||||||
VIR_FREE(sourceList.sources);
|
VIR_FREE(sourceList.sources);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -4088,7 +4088,6 @@ testStorageFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virStoragePoolSourceFree(source);
|
virStoragePoolSourceFree(source);
|
||||||
VIR_FREE(source);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user