提交 0ca51d5c 编写于 作者: M Michal Privoznik

Adapt to VIR_STRDUP and VIR_STRNDUP in src/nwfilter/*

上级 e3221e64
...@@ -133,11 +133,11 @@ struct _virNWFilterSnoopReq { ...@@ -133,11 +133,11 @@ struct _virNWFilterSnoopReq {
virNWFilterTechDriverPtr techdriver; virNWFilterTechDriverPtr techdriver;
char *ifname; char *ifname;
int ifindex; int ifindex;
const char *linkdev; char *linkdev;
enum virDomainNetType nettype; enum virDomainNetType nettype;
char ifkey[VIR_IFKEY_LEN]; char ifkey[VIR_IFKEY_LEN];
virMacAddr macaddr; virMacAddr macaddr;
const char *filtername; char *filtername;
virNWFilterHashTablePtr vars; virNWFilterHashTablePtr vars;
virNWFilterDriverStatePtr driver; virNWFilterDriverStatePtr driver;
/* start and end of lease list, ordered by lease time */ /* start and end of lease list, ordered by lease time */
...@@ -1110,10 +1110,8 @@ virNWFilterSnoopDHCPOpen(const char *ifname, virMacAddr *mac, ...@@ -1110,10 +1110,8 @@ virNWFilterSnoopDHCPOpen(const char *ifname, virMacAddr *mac,
* generate much more traffic than if we filtered by VM and * generate much more traffic than if we filtered by VM and
* braodcast MAC as well * braodcast MAC as well
*/ */
if (!(ext_filter = strdup(filter))) { if (VIR_STRDUP(ext_filter, filter) < 0)
virReportOOMError();
return NULL; return NULL;
}
} }
handle = pcap_create(ifname, pcap_errbuf); handle = pcap_create(ifname, pcap_errbuf);
...@@ -1408,7 +1406,7 @@ virNWFilterDHCPSnoopThread(void *req0) ...@@ -1408,7 +1406,7 @@ virNWFilterDHCPSnoopThread(void *req0)
fds[i].fd = pcap_fileno(pcapConf[i].handle); fds[i].fd = pcap_fileno(pcapConf[i].handle);
} }
tmp = virNetDevGetIndex(req->ifname, &ifindex); tmp = virNetDevGetIndex(req->ifname, &ifindex);
threadkey = strdup(req->threadkey); ignore_value(VIR_STRDUP(threadkey, req->threadkey));
worker = virThreadPoolNew(1, 1, 0, worker = virThreadPoolNew(1, 1, 0,
virNWFilterDHCPDecodeWorker, virNWFilterDHCPDecodeWorker,
req); req);
...@@ -1631,15 +1629,17 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver, ...@@ -1631,15 +1629,17 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
req->driver = driver; req->driver = driver;
req->techdriver = techdriver; req->techdriver = techdriver;
tmp = virNetDevGetIndex(ifname, &req->ifindex); tmp = virNetDevGetIndex(ifname, &req->ifindex);
req->linkdev = linkdev ? strdup(linkdev) : NULL;
req->nettype = nettype; req->nettype = nettype;
req->ifname = strdup(ifname);
virMacAddrSet(&req->macaddr, macaddr); virMacAddrSet(&req->macaddr, macaddr);
req->filtername = strdup(filtername);
req->vars = virNWFilterHashTableCreate(0); req->vars = virNWFilterHashTableCreate(0);
req->linkdev = NULL;
if (VIR_STRDUP(req->ifname, ifname) < 0 ||
VIR_STRDUP(req->filtername, filtername) < 0 ||
VIR_STRDUP(req->linkdev, linkdev) < 0)
goto exit_snoopreqput;
if (!req->ifname || !req->filtername || !req->vars || tmp < 0 || if (!req->vars || tmp < 0) {
(linkdev != NULL && req->linkdev == NULL)) {
virReportOOMError(); virReportOOMError();
goto exit_snoopreqput; goto exit_snoopreqput;
} }
......
...@@ -221,8 +221,8 @@ nwfilterStateInitialize(bool privileged, ...@@ -221,8 +221,8 @@ nwfilterStateInitialize(bool privileged,
goto error; goto error;
} }
if ((base = strdup(SYSCONFDIR "/libvirt")) == NULL) if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0)
goto out_of_memory; goto error;
if (virAsprintf(&driverState->configDir, if (virAsprintf(&driverState->configDir,
"%s/nwfilter", base) == -1) "%s/nwfilter", base) == -1)
...@@ -454,9 +454,8 @@ nwfilterConnectListNWFilters(virConnectPtr conn, ...@@ -454,9 +454,8 @@ nwfilterConnectListNWFilters(virConnectPtr conn,
nwfilterDriverLock(driver); nwfilterDriverLock(driver);
for (i = 0 ; i < driver->nwfilters.count && got < nnames ; i++) { for (i = 0 ; i < driver->nwfilters.count && got < nnames ; i++) {
virNWFilterObjLock(driver->nwfilters.objs[i]); virNWFilterObjLock(driver->nwfilters.objs[i]);
if (!(names[got] = strdup(driver->nwfilters.objs[i]->def->name))) { if (VIR_STRDUP(names[got], driver->nwfilters.objs[i]->def->name) < 0) {
virNWFilterObjUnlock(driver->nwfilters.objs[i]); virNWFilterObjUnlock(driver->nwfilters.objs[i]);
virReportOOMError();
goto cleanup; goto cleanup;
} }
got++; got++;
......
...@@ -2982,7 +2982,7 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst, ...@@ -2982,7 +2982,7 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst,
switch (protoidx) { switch (protoidx) {
case L2_PROTO_MAC_IDX: case L2_PROTO_MAC_IDX:
protostr = strdup(""); ignore_value(VIR_STRDUP(protostr, ""));
break; break;
case L2_PROTO_STP_IDX: case L2_PROTO_STP_IDX:
ignore_value(virAsprintf(&protostr, "-d " NWFILTER_MAC_BGA " ")); ignore_value(virAsprintf(&protostr, "-d " NWFILTER_MAC_BGA " "));
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "nwfilter_learnipaddr.h" #include "nwfilter_learnipaddr.h"
#include "virnetdev.h" #include "virnetdev.h"
#include "datatypes.h" #include "datatypes.h"
#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_NWFILTER #define VIR_FROM_THIS VIR_FROM_NWFILTER
...@@ -866,9 +867,7 @@ __virNWFilterInstantiateFilter(const unsigned char *vmuuid, ...@@ -866,9 +867,7 @@ __virNWFilterInstantiateFilter(const unsigned char *vmuuid,
} }
virMacAddrFormat(macaddr, vmmacaddr); virMacAddrFormat(macaddr, vmmacaddr);
str_macaddr = strdup(vmmacaddr); if (VIR_STRDUP(str_macaddr, vmmacaddr) < 0) {
if (!str_macaddr) {
virReportOOMError();
rc = -1; rc = -1;
goto err_exit; goto err_exit;
} }
......
...@@ -705,11 +705,8 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver, ...@@ -705,11 +705,8 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
if (virNWFilterHashTablePutAll(filterparams, ht) < 0) if (virNWFilterHashTablePutAll(filterparams, ht) < 0)
goto err_free_ht; goto err_free_ht;
req->filtername = strdup(filtername); if (VIR_STRDUP(req->filtername, filtername) < 0)
if (req->filtername == NULL) {
virReportOOMError();
goto err_free_ht; goto err_free_ht;
}
if (virStrcpyStatic(req->ifname, ifname) == NULL) { if (virStrcpyStatic(req->ifname, ifname) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册