mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-09 06:25:19 +00:00
driver: Don't leak saved error in virGetConnectGeneric()
Recently, a new code was added to virGetConnectGeneric() that saves the original error into a variable so that it's not lost in virConnectClose() called under the 'error' label. However, the error saving code uses virSaveLastError() + virSetError() combo which leaks the memory allocated for the error copy. Using virErrorPreserveLast() + virErrorRestore() does the same job without the memleak. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
6eac856e7c
commit
d0e0a909fa
@ -138,7 +138,7 @@ static virConnectPtr
|
|||||||
virGetConnectGeneric(virThreadLocal *threadPtr, const char *name)
|
virGetConnectGeneric(virThreadLocal *threadPtr, const char *name)
|
||||||
{
|
{
|
||||||
virConnectPtr conn;
|
virConnectPtr conn;
|
||||||
virErrorPtr saved;
|
virErrorPtr orig_err;
|
||||||
|
|
||||||
if (virConnectCacheInitialize() < 0)
|
if (virConnectCacheInitialize() < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -178,9 +178,9 @@ virGetConnectGeneric(virThreadLocal *threadPtr, const char *name)
|
|||||||
return conn;
|
return conn;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
saved = virSaveLastError();
|
virErrorPreserveLast(&orig_err);
|
||||||
virConnectClose(conn);
|
virConnectClose(conn);
|
||||||
virSetError(saved);
|
virErrorRestore(&orig_err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user