[libvirt] [PATCH V1 3/5] tests: fix resource leak

Osier Yang jyang at redhat.com
Fri May 4 13:57:16 UTC 2012


On 2012年05月04日 19:54, Stefan Berger wrote:
> Error: RESOURCE_LEAK:
> /libvirt/tests/qemuxml2argvtest.c:47:
> alloc_arg: Calling allocation function "virAlloc" on "ret".
> /libvirt/src/util/memory.c:101:
> alloc_fn: Storage is returned from allocation function "calloc".
> /libvirt/src/util/memory.c:101:
> var_assign: Assigning: "*((void **)ptrptr)" = "calloc(1UL, size)".
> /libvirt/tests/qemuxml2argvtest.c:54:
> leaked_storage: Variable "ret" going out of scope leaks the storage it points to.
>
> ---
>   tests/qemuxml2argvtest.c |    4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> Index: libvirt-acl/tests/qemuxml2argvtest.c
> ===================================================================
> --- libvirt-acl.orig/tests/qemuxml2argvtest.c
> +++ libvirt-acl/tests/qemuxml2argvtest.c
> @@ -50,8 +50,10 @@ fakeSecretLookupByUsage(virConnectPtr co
>       ret->magic = VIR_SECRET_MAGIC;
>       ret->refs = 1;
>       ret->usageID = strdup(usageID);
> -    if (!ret->usageID)
> +    if (!ret->usageID) {
> +        VIR_FREE(ret);
>           return NULL;
> +    }
>       ret->conn = conn;
>       conn->refs++;
>       return ret;

ACK

Osier




More information about the libvir-list mailing list