sixaxis: Fix memory leaks
authorGopal Tiwari <gtiwari@redhat.com>
Tue, 31 May 2022 07:41:08 +0000 (13:11 +0530)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
While performing static tool analysis using coverity
found following reports for resouse leak

bluez-5.64/plugins/sixaxis.c:425: alloc_arg:
"get_pairing_type_for_device" allocates memory that is
stored into "sysfs_path".

bluez-5.64/plugins/sixaxis.c:428: leaked_storage: Variable "sysfs_path"
going out of scope leaks the storage it points to.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
plugins/sixaxis.c

index fee6f59..ec5910d 100755 (executable)
@@ -423,10 +423,15 @@ static void device_added(struct udev_device *udevice)
 
        cp = get_pairing_type_for_device(udevice, &bus, &sysfs_path);
        if (!cp || (cp->type != CABLE_PAIRING_SIXAXIS &&
-                               cp->type != CABLE_PAIRING_DS4))
+                               cp->type != CABLE_PAIRING_DS4)) {
+               g_free(sysfs_path);
                return;
-       if (bus != BUS_USB)
+       }
+
+       if (bus != BUS_USB) {
+               g_free(sysfs_path);
                return;
+       }
 
        info("sixaxis: compatible device connected: %s (%04X:%04X %s)",
                                cp->name, cp->vid, cp->pid, sysfs_path);