[libvirt] [cim][PATCH 0/2] memory leak fixes in CIM provider

In some instances, asprintf allocated memory is not freed resulting in a slow memory leak. Adam Majer (2): Fix memory leak in set_other_id_info Fix memory leak in set_input_props src/Virt_ComputerSystem.c | 2 ++ src/Virt_SettingsDefineCapabilities.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) -- 2.13.6

model was allocated by asprintf but never freed after usage and assignment. Signed-off-by: Adam Majer <amajer@suse.de> --- src/Virt_ComputerSystem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Virt_ComputerSystem.c b/src/Virt_ComputerSystem.c index da07f93..b4930ac 100644 --- a/src/Virt_ComputerSystem.c +++ b/src/Virt_ComputerSystem.c @@ -417,6 +417,8 @@ static int set_other_id_info(const CMPIBroker *broker, CMPI_string); } + free(model); + CMSetProperty(instance, "OtherIdentifyingInfo", &id_info, CMPI_stringA); -- 2.13.6

When caption is specified, cap was allocated and assigned a new pointer while the old never freed. Free cap before replacing it. get_input_dev_caption only returns valid cap pointer on success, so do not try to free it on failure. Signed-off-by: Adam Majer <amajer@suse.de> --- src/Virt_SettingsDefineCapabilities.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Virt_SettingsDefineCapabilities.c b/src/Virt_SettingsDefineCapabilities.c index 85cb27a..0a1d61e 100644 --- a/src/Virt_SettingsDefineCapabilities.c +++ b/src/Virt_SettingsDefineCapabilities.c @@ -1978,9 +1978,9 @@ static CMPIStatus set_input_props(const CMPIObjectPath *ref, CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *inst; char *cap; + char *tmp; if (get_input_dev_caption(type, bus, &cap) != 1) { - free(cap); cu_statusf(_BROKER, &s, CMPI_RC_ERR_NOT_FOUND, "Unable to build input caption"); @@ -1988,12 +1988,14 @@ static CMPIStatus set_input_props(const CMPIObjectPath *ref, } if (caption != NULL) { - if (asprintf(&cap, "%s %s", caption, cap) == -1) { + if (asprintf(&tmp, "%s %s", caption, cap) == -1) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_NOT_FOUND, "Unable to build input caption"); goto out; } + free(cap); + cap = tmp; } inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_INPUT, DEVICE_RASD); -- 2.13.6
participants (1)
-
Adam Majer