[PATCH 2/2] Fix memory leak in set_input_props

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx>
---
 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@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux