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
|
||||
virStoragePoolSourceFree(virStoragePoolSourcePtr source) {
|
||||
virStoragePoolSourceClear(virStoragePoolSourcePtr source)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!source)
|
||||
@ -294,6 +295,13 @@ virStoragePoolSourceFree(virStoragePoolSourcePtr source) {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
virStoragePoolSourceFree(virStoragePoolSourcePtr source)
|
||||
{
|
||||
virStoragePoolSourceClear(source);
|
||||
VIR_FREE(source);
|
||||
}
|
||||
|
||||
void
|
||||
virStoragePoolDefFree(virStoragePoolDefPtr def) {
|
||||
if (!def)
|
||||
@ -301,7 +309,7 @@ virStoragePoolDefFree(virStoragePoolDefPtr def) {
|
||||
|
||||
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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -992,14 +992,15 @@ virStoragePoolObjClearVols;
|
||||
virStoragePoolObjDeleteDef;
|
||||
virStoragePoolObjFindByName;
|
||||
virStoragePoolObjFindByUUID;
|
||||
virStoragePoolSourceFindDuplicateDevices;
|
||||
virStoragePoolObjIsDuplicate;
|
||||
virStoragePoolSourceFindDuplicate;
|
||||
virStoragePoolObjListFree;
|
||||
virStoragePoolObjLock;
|
||||
virStoragePoolObjRemove;
|
||||
virStoragePoolObjSaveDef;
|
||||
virStoragePoolObjUnlock;
|
||||
virStoragePoolSourceClear;
|
||||
virStoragePoolSourceFindDuplicate;
|
||||
virStoragePoolSourceFindDuplicateDevices;
|
||||
virStoragePoolSourceFree;
|
||||
virStoragePoolSourceListFormat;
|
||||
virStoragePoolSourceListNewSource;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -611,7 +611,6 @@ cleanup:
|
||||
VIR_FREE(targets);
|
||||
VIR_FREE(portal);
|
||||
virStoragePoolSourceFree(source);
|
||||
VIR_FREE(source);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -4088,7 +4088,6 @@ testStorageFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
|
||||
cleanup:
|
||||
virStoragePoolSourceFree(source);
|
||||
VIR_FREE(source);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user