[libvirt] [PATCH] openvz_driver.c: avoid leak on OOM error path

It looks like openvzFreeDriver cannot call VIR_FREE on its buffer argument, because of the use in the function that just happens to be a few lines below. These are the only two uses of openvzFreeDriver.
From 0a616cd03cca9c9d89f23dadd52cd23c30789aca Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 15 Feb 2010 18:33:38 +0100 Subject: [PATCH] openvz_driver.c: avoid leak on OOM error path
* src/openvz/openvz_driver.c (openvzOpen): Free "driver" buffer upon failure. --- src/openvz/openvz_driver.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 68d0398..3a8a82f 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1245,22 +1245,23 @@ static virDrvOpenStatus openvzOpen(virConnectPtr conn, goto cleanup; if (openvzExtractVersion(conn, driver) < 0) goto cleanup; conn->privateData = driver; return VIR_DRV_OPEN_SUCCESS; cleanup: openvzFreeDriver(driver); + VIR_FREE(driver); return VIR_DRV_OPEN_ERROR; }; static int openvzClose(virConnectPtr conn) { struct openvz_driver *driver = conn->privateData; openvzFreeDriver(driver); conn->privateData = NULL; return 0; } -- 1.7.0.181.g41533

2010/2/15 Jim Meyering <jim@meyering.net>:
It looks like openvzFreeDriver cannot call VIR_FREE on its buffer argument, because of the use in the function that just happens to be a few lines below. These are the only two uses of openvzFreeDriver.
From 0a616cd03cca9c9d89f23dadd52cd23c30789aca Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 15 Feb 2010 18:33:38 +0100 Subject: [PATCH] openvz_driver.c: avoid leak on OOM error path
* src/openvz/openvz_driver.c (openvzOpen): Free "driver" buffer upon failure. --- src/openvz/openvz_driver.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 68d0398..3a8a82f 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1245,22 +1245,23 @@ static virDrvOpenStatus openvzOpen(virConnectPtr conn, goto cleanup;
if (openvzExtractVersion(conn, driver) < 0) goto cleanup;
conn->privateData = driver;
return VIR_DRV_OPEN_SUCCESS;
cleanup: openvzFreeDriver(driver); + VIR_FREE(driver); return VIR_DRV_OPEN_ERROR; };
static int openvzClose(virConnectPtr conn) { struct openvz_driver *driver = conn->privateData;
openvzFreeDriver(driver); conn->privateData = NULL;
return 0; } -- 1.7.0.181.g41533
Why do you think openvzFreeDriver must not VIR_FREE the driver object? The driver object is allocated per connection in openvzOpen, so openvzClose has to VIR_FREE it. Matthias

Matthias Bolte wrote: ...
Why do you think openvzFreeDriver must not VIR_FREE the driver object? The driver object is allocated per connection in openvzOpen, so openvzClose has to VIR_FREE it.
I was lazy, and assumed there wouldn't be so many leaks. I should have looked. Here's a better patch. Thanks for keeping me honest.
From 2b865b8f955d88bb687a429efd636dd2212cd13b Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 15 Feb 2010 18:33:38 +0100 Subject: [PATCH] openvz (openvzFreeDriver): avoid leaks
* src/openvz/openvz_conf.c (openvzFreeDriver): Also free driver buffer. Based on a suggestion from Matthias Bolte. --- src/openvz/openvz_conf.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index f4b8199..51dbde5 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -427,6 +427,7 @@ openvzFreeDriver(struct openvz_driver *driver) virDomainObjListDeinit(&driver->domains); virCapabilitiesFree(driver->caps); + VIR_FREE(driver); } -- 1.7.0.181.g41533

2010/2/15 Jim Meyering <jim@meyering.net>:
Matthias Bolte wrote: ...
Why do you think openvzFreeDriver must not VIR_FREE the driver object? The driver object is allocated per connection in openvzOpen, so openvzClose has to VIR_FREE it.
I was lazy, and assumed there wouldn't be so many leaks. I should have looked.
Here's a better patch. Thanks for keeping me honest.
:-)
From 2b865b8f955d88bb687a429efd636dd2212cd13b Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 15 Feb 2010 18:33:38 +0100 Subject: [PATCH] openvz (openvzFreeDriver): avoid leaks
* src/openvz/openvz_conf.c (openvzFreeDriver): Also free driver buffer. Based on a suggestion from Matthias Bolte. --- src/openvz/openvz_conf.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index f4b8199..51dbde5 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -427,6 +427,7 @@ openvzFreeDriver(struct openvz_driver *driver)
virDomainObjListDeinit(&driver->domains); virCapabilitiesFree(driver->caps); + VIR_FREE(driver); }
-- 1.7.0.181.g41533
ACK Matthias
participants (2)
-
Jim Meyering
-
Matthias Bolte