提交 a55eaced 编写于 作者: J John Ferlan

nwfilter: Don't have virNWFilterIPAddrMapAddIPAddr consume input

On pure success paths, virNWFilterIPAddrMapAddIPAddr was validly
consuming the input @addr; however, on failure paths it was possible
that virNWFilterVarValueCreateSimple succeed, but virNWFilterHashTablePut
failed resulting in virNWFilterVarValueFree being called to clean
up @val which also cleaned up the input @addr. Thus the caller had
no way to determine on failure whether it too should clean up the
passed parameter.

Instead, let's create a copy of the input @addr, then handle that
properly in the API allowing/forcing the caller to free it's own
copy of the input parameter.
上级 03970217
......@@ -26,7 +26,9 @@
#include "internal.h"
#include "viralloc.h"
#include "virerror.h"
#include "virstring.h"
#include "datatypes.h"
#include "nwfilter_params.h"
#include "nwfilter_ipaddrmap.h"
......@@ -51,28 +53,35 @@ int
virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *addr)
{
int ret = -1;
char *addrCopy;
virNWFilterVarValuePtr val;
if (VIR_STRDUP(addrCopy, addr) < 0)
return -1;
virMutexLock(&ipAddressMapLock);
val = virHashLookup(ipAddressMap->hashTable, ifname);
if (!val) {
val = virNWFilterVarValueCreateSimple(addr);
val = virNWFilterVarValueCreateSimple(addrCopy);
if (!val)
goto cleanup;
addrCopy = NULL;
ret = virNWFilterHashTablePut(ipAddressMap, ifname, val);
if (ret < 0)
virNWFilterVarValueFree(val);
goto cleanup;
} else {
if (virNWFilterVarValueAddValue(val, addr) < 0)
if (virNWFilterVarValueAddValue(val, addrCopy) < 0)
goto cleanup;
addrCopy = NULL;
}
ret = 0;
cleanup:
virMutexUnlock(&ipAddressMapLock);
VIR_FREE(addrCopy);
return ret;
}
......
......@@ -476,9 +476,6 @@ virNWFilterSnoopIPLeaseInstallRule(virNWFilterSnoopIPLeasePtr ipl,
if (virNWFilterIPAddrMapAddIPAddr(req->ifname, ipaddr) < 0)
goto exit_snooprequnlock;
/* ipaddr now belongs to the map */
ipaddr = NULL;
if (!instantiate) {
rc = 0;
goto exit_snooprequnlock;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册