Page 1 of 1

Small memory leak bugfix

Posted: 02 Nov 2021, 11:23
by sfstudio

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);
                

Re: Small memory leak bugfix

Posted: 02 Nov 2021, 15:47
by LOM
Right, don't allocate memory until you know that you'll need it. 8)

Re: Small memory leak bugfix

Posted: 10 Nov 2021, 22:15
by sfstudio
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);

Re: Small memory leak bugfix

Posted: 23 Nov 2023, 09:51
by ana167
I am extremely intrigued by this subject. Even though I have read numerous articles, I believe yours is the best. play globle game

Re: Small memory leak bugfix

Posted: 29 Dec 2023, 14:46
by gbwhatspro1
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.