aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Bolte <matthias.bolte@googlemail.com>2010-05-03 12:26:42 +0200
committerMatthias Bolte <matthias.bolte@googlemail.com>2010-05-03 21:59:16 +0200
commit254ade373d29153d7e5fe579086f86e7010ab4d8 (patch)
tree7c16a7924d942e10fe87a26159948be50567969d
parentFix memory leaks in cmdInterfaceEdit and cmdNWFilterEdit. (diff)
downloadlibvirt-254ade373d29153d7e5fe579086f86e7010ab4d8.tar.gz
libvirt-254ade373d29153d7e5fe579086f86e7010ab4d8.tar.bz2
libvirt-254ade373d29153d7e5fe579086f86e7010ab4d8.zip
dnsmasq.c: Fix OOM error reporting
Also do some indentation clean up.
-rw-r--r--src/util/dnsmasq.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/util/dnsmasq.c b/src/util/dnsmasq.c
index 1cb5f212f..2d5788440 100644
--- a/src/util/dnsmasq.c
+++ b/src/util/dnsmasq.c
@@ -84,12 +84,12 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile,
if (name) {
if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s,%s",
- mac, ip, name) < 0) {
+ mac, ip, name) < 0) {
goto alloc_error;
}
} else {
if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s",
- mac, ip) < 0) {
+ mac, ip) < 0) {
goto alloc_error;
}
}
@@ -99,9 +99,8 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile,
return 0;
alloc_error:
- virReportSystemError(ENOMEM,
- _("Failed to add dhcp host entry: mac=%s, ip=%s, name=%s\n"),
- mac, ip, (name ? name : "(null)"));
+ virReportOOMError();
+
return -1;
}
@@ -112,20 +111,23 @@ hostsfileNew(const char *name,
int err;
dnsmasqHostsfile *hostsfile;
- if (VIR_ALLOC(hostsfile) < 0)
+ if (VIR_ALLOC(hostsfile) < 0) {
+ virReportOOMError();
return NULL;
+ }
hostsfile->hosts = NULL;
hostsfile->nhosts = 0;
if (virAsprintf(&hostsfile->path, "%s/%s.%s", config_dir, name,
- DNSMASQ_HOSTSFILE_SUFFIX) < 0) {
+ DNSMASQ_HOSTSFILE_SUFFIX) < 0) {
+ virReportOOMError();
goto error;
}
if ((err = virFileMakePath(config_dir))) {
virReportSystemError(err, _("cannot create config directory '%s'"),
- config_dir);
+ config_dir);
goto error;
}
@@ -201,11 +203,11 @@ static int
hostsfileSave(dnsmasqHostsfile *hostsfile)
{
int err = hostsfileWrite(hostsfile->path, hostsfile->hosts,
- hostsfile->nhosts);
+ hostsfile->nhosts);
if (err < 0) {
virReportSystemError(err, _("cannot write config file '%s'"),
- hostsfile->path);
+ hostsfile->path);
return -1;
}
@@ -220,7 +222,7 @@ hostsfileDelete(dnsmasqHostsfile *hostsfile)
if (unlink(hostsfile->path) < 0) {
virReportSystemError(errno, _("cannot remove config file '%s'"),
- hostsfile->path);
+ hostsfile->path);
return -1;
}
@@ -240,8 +242,10 @@ dnsmasqContextNew(const char *network_name,
{
dnsmasqContext *ctx;
- if (VIR_ALLOC(ctx) < 0)
+ if (VIR_ALLOC(ctx) < 0) {
+ virReportOOMError();
return NULL;
+ }
if (!(ctx->hostsfile = hostsfileNew(network_name, config_dir)))
goto error;