uclient-fetch: fix potential memory leaks
authorPetr Štetiar <ynezz@true.cz>
Tue, 8 Dec 2020 16:45:19 +0000 (17:45 +0100)
committerPetr Štetiar <ynezz@true.cz>
Fri, 11 Dec 2020 10:17:22 +0000 (11:17 +0100)
Fixes following issue reported by clang-12 static analyzer:

 uclient-fetch.c:612:25: warning: Potential leak of memory pointed to by 'username' [unix.Malloc]
                                 memset(optarg, '*', strlen(optarg));
                                                     ^~~~~~~~~~~~~~
 uclient-fetch.c:618:25: warning: Potential leak of memory pointed to by 'password' [unix.Malloc]
                                 memset(optarg, '*', strlen(optarg));
                                                     ^~~~~~~~~~~~~~

Signed-off-by: Petr Štetiar <ynezz@true.cz>
uclient-fetch.c

index 0c7a1232f2565c96beb8a31fd83c460ebb6d987e..1c66ac6d33ae6d5cf24bd8379e7d5233746ca1b5 100644 (file)
@@ -608,13 +608,13 @@ int main(int argc, char **argv)
                        case L_USER:
                                if (!strlen(optarg))
                                        break;
-                               username = strdup(optarg);
+                               username = strdupa(optarg);
                                memset(optarg, '*', strlen(optarg));
                                break;
                        case L_PASSWORD:
                                if (!strlen(optarg))
                                        break;
-                               password = strdup(optarg);
+                               password = strdupa(optarg);
                                memset(optarg, '*', strlen(optarg));
                                break;
                        case L_USER_AGENT: