• Subject: [libvirt] [cim][PATCH 0/2] memory leak fixes in CIM provider
  • Author: Adam Majer
  • Date: Jan. 9, 2018, 12:20 p.m.
  • Patches: 2 / 2
Changeset
src/Virt_ComputerSystem.c             | 2 ++
src/Virt_SettingsDefineCapabilities.c | 6 ++++--
2 files changed, 6 insertions(+), 2 deletions(-)
Git apply log
Switched to a new branch '20180109122038.20938-1-amajer@suse.de'
Applying: Fix memory leak in set_other_id_info
error: sha1 information is lacking or useless (src/Virt_ComputerSystem.c).
error: could not build fake ancestor
Patch failed at 0001 Fix memory leak in set_other_id_info
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Failed to apply patch:
[libvirt] [PATCH 1/2] Fix memory leak in set_other_id_info
[libvirt] [cim][PATCH 0/2] memory leak fixes in CIM provider
Posted by Adam Majer, 1 week ago
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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 1/2] Fix memory leak in set_other_id_info
Posted by Adam Majer, 1 week ago
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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 2/2] Fix memory leak in set_input_props
Posted by Adam Majer, 1 week ago
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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list