From 2b3c49b6ab096223a9bda27cc24cd66f294758cc Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Sat, 1 Dec 2007 15:45:25 +0000 Subject: [PATCH] Fix numerous memory leaks --- ChangeLog | 9 +++++++++ src/hash.c | 1 + src/iptables.c | 2 +- src/qemu_driver.c | 3 +++ src/remote_internal.c | 15 ++++----------- src/virsh.c | 13 ++++++++++--- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 11fc36cf81..ad5f279de3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Sat Dec 1 10:42:34 EST 2007 Daniel P. Berrange + + * src/hash.c: reset error object when releasing connection + * src/iptables.c: don't strdup() param passed to strcmp() + * src/qemu_driver.c: free TLS directory path in driver shutdown + * src/remote_internal.c: don't strdup() params for virRaiseError + * src/virsh.c: reset global error object at shutdown. Release + connection state during abnormal shutdown + Sat Dec 1 10:22:34 EST 2007 Daniel P. Berrange * src/qemu_driver.c: Fix off-by-1 buffer NULL termination in diff --git a/src/hash.c b/src/hash.c index 5da1accd51..2b4b6ece6f 100644 --- a/src/hash.c +++ b/src/hash.c @@ -726,6 +726,7 @@ virFreeConnect(virConnectPtr conn) { virHashFree(conn->networks, (virHashDeallocator) virNetworkFreeName); if (conn->hashes_mux != NULL) xmlFreeMutex(conn->hashes_mux); + virResetError(&conn->err); free(conn); return(0); } diff --git a/src/iptables.c b/src/iptables.c index 449782b322..6de6008bb5 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -246,7 +246,7 @@ iptRulesRemove(iptRules *rules, int i; for (i = 0; i < rules->nrules; i++) - if (!strcmp(rules->rules[i].rule, strdup(rule))) + if (!strcmp(rules->rules[i].rule, rule)) break; if (i >= rules->nrules) diff --git a/src/qemu_driver.c b/src/qemu_driver.c index 9614532fbd..a6982613ca 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -341,6 +341,9 @@ qemudShutdown(void) { if (qemu_driver->networkAutostartDir) free(qemu_driver->networkAutostartDir); + if (qemu_driver->vncTLSx509certdir) + free(qemu_driver->vncTLSx509certdir); + if (qemu_driver->brctl) brShutdown(qemu_driver->brctl); if (qemu_driver->iptables) diff --git a/src/remote_internal.c b/src/remote_internal.c index 40c12c7c04..a8227f3a82 100644 --- a/src/remote_internal.c +++ b/src/remote_internal.c @@ -3052,20 +3052,13 @@ server_error (virConnectPtr conn, remote_error *err) dom = err->dom ? get_nonnull_domain (conn, *err->dom) : NULL; net = err->net ? get_nonnull_network (conn, *err->net) : NULL; - /* These strings are nullable. OK to ignore the return value - * of strdup since these strings are informational. - */ - char *str1 = err->str1 ? strdup (*err->str1) : NULL; - char *str2 = err->str2 ? strdup (*err->str2) : NULL; - char *str3 = err->str3 ? strdup (*err->str3) : NULL; - - char *message = err->message ? strdup (*err->message) : NULL; - __virRaiseError (conn, dom, net, err->domain, err->code, err->level, - str1, str2, str3, + err->str1 ? *err->str1 : NULL, + err->str2 ? *err->str2 : NULL, + err->str3 ? *err->str3 : NULL, err->int1, err->int2, - "%s", message); + "%s", err->message ? *err->message : NULL); } /* get_nonnull_domain and get_nonnull_network turn an on-wire diff --git a/src/virsh.c b/src/virsh.c index c8bedc14f0..ccd85be0e1 100644 --- a/src/virsh.c +++ b/src/virsh.c @@ -4780,7 +4780,8 @@ static int vshDeinit(vshControl * ctl) { vshCloseLogFile(ctl); - + if (ctl->name) + free(ctl->name); if (ctl->conn) { if (virConnectClose(ctl->conn) != 0) { ctl->conn = NULL; /* prevent recursive call from vshError() */ @@ -4788,6 +4789,8 @@ vshDeinit(vshControl * ctl) "failed to disconnect from the hypervisor"); } } + virResetLastError(); + return TRUE; } @@ -4985,11 +4988,15 @@ main(int argc, char **argv) ctl->name = strdup(defaultConn); } - if (!vshParseArgv(ctl, argc, argv)) + if (!vshParseArgv(ctl, argc, argv)) { + vshDeinit(ctl); exit(EXIT_FAILURE); + } - if (!vshInit(ctl)) + if (!vshInit(ctl)) { + vshDeinit(ctl); exit(EXIT_FAILURE); + } if (!ctl->imode) { ret = vshCommandRun(ctl, ctl->cmd);