The C Source, Patches and (shudder!) Bugs
Post Reply
sfstudio
Posts: 2
Joined: 02 Nov 2021, 11:21

Small memory leak bugfix

Post by sfstudio » 02 Nov 2021, 11:23

Code: Select all

--- usb_modeswitch.c    2020-07-10 20:48:03.000000000 +0500
+++ usb_modeswitch.c.my 2021-11-02 14:17:45.585189952 +0500
@@ -376,7 +376,7 @@
                        case 'J': ModeMap = ModeMap + HUAWEINEW_MODE; break;
                        case 'X': ModeMap = ModeMap + HUAWEIALT_MODE; break;
                        case 'S': ModeMap = ModeMap + SIERRA_MODE; break;
-                       case 'O': ModeMap = ModeMap + SONY_MODE; break;; break;
+                       case 'O': ModeMap = ModeMap + SONY_MODE; break;
                        case 'B': ModeMap = ModeMap + QISDA_MODE; break;
                        case 'E': ModeMap = ModeMap + QUANTA_MODE; break;
                        case 'G': ModeMap = ModeMap + GCT_MODE; break;
@@ -1721,13 +1724,13 @@
        if (!vendor || *productList == '\0')
                return NULL;

-       listcopy = malloc(strlen(productList)+1);
-
        if (libusb_get_device_list(ctx, &devs) < 0) {
                perror("Libusb failed to get USB access!");
                return 0;
        }

+       listcopy = malloc(strlen(productList)+1);
+
        while ((dev = devs[i++]) != NULL) {
                struct libusb_device_descriptor descriptor;
                libusb_get_device_descriptor(dev, &descriptor);
                

LOM
Posts: 1404
Joined: 11 Jul 2012, 15:14
Location: Koh Samui, TH

Re: Small memory leak bugfix

Post by LOM » 02 Nov 2021, 15:47

Right, don't allocate memory until you know that you'll need it. 8)

sfstudio
Posts: 2
Joined: 02 Nov 2021, 11:21

Re: Small memory leak bugfix

Post by sfstudio » 10 Nov 2021, 22:15

Hi. Next...

In code periodic call search devices function in code

Code: Select all

        dev = search_devices(&numDefaults, DefaultVendor, DefaultProductList, TargetClass,
                Configuration, searchMode);
Variable dev declarated as static struct libusb_device *dev = NULL;

search_devices, in error case, must be return NULL, not 0.

Code: Select all

--- a/user/usb_modeswitch/usb_modeswitch.c
+++ b/user/usb_modeswitch/usb_modeswitch.c
@@ -1726,7 +1726,7 @@ struct libusb_device* search_devices( int *numFound, int vendor, char* productLi
.
        if (libusb_get_device_list(ctx, &devs) < 0) {
                perror("Libusb failed to get USB access!");
-               return 0;
+               return NULL;
        }
.
        listcopy = malloc(strlen(productList)+1);

ana167
Posts: 1
Joined: 23 Nov 2023, 09:50

Re: Small memory leak bugfix

Post by ana167 » 23 Nov 2023, 09:51

I am extremely intrigued by this subject. Even though I have read numerous articles, I believe yours is the best. play globle game

gbwhatspro1
Posts: 1
Joined: 29 Dec 2023, 14:22
Contact:

Re: Small memory leak bugfix

Post by gbwhatspro1 » 29 Dec 2023, 14:46

One of the frustrations of messaging apps is the ability for users to delete sent messages, leaving the recipient in the dark about the content. GB Whatsapp Apk addresses this concern with the introduction of the Anti-Revoke feature.

Post Reply