opkg: Fix a small memory leak in opkg_download.
[oweals/opkg-lede.git] / libopkg / opkg_download.c
index 1d882a14e1852d9492fcb30aafbb23a2b65a2f80..629aa798aa181f500b55fbc13127fd95efb987bf 100644 (file)
@@ -49,6 +49,7 @@ int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name
        opkg_message(conf,OPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
        ret = file_copy(src + 5, dest_file_name);
        opkg_message(conf,OPKG_INFO,"Done\n");
+        free(src_basec);
        return ret;
     }
 
@@ -58,6 +59,7 @@ int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name
        opkg_message(conf,OPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
                __FUNCTION__, tmp_file_location, strerror(errno));
        free(tmp_file_location);
+        free(src_basec);
        return errno;
     }
 
@@ -99,19 +101,26 @@ int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name
            free (userpwd);
        }
        res = curl_easy_perform (curl);
-       curl_easy_cleanup (curl);
        fclose (file);
        if (res)
        {
            long error_code;
            curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &error_code);
            opkg_message(conf, OPKG_ERROR, "Failed to download %s, error %d\n", src, error_code);
+           free(tmp_file_location);
+            free(src_basec);
+           curl_easy_cleanup (curl);
            return res;
        }
+       curl_easy_cleanup (curl);
 
     }
     else
+    {
+       free(tmp_file_location);
+        free(src_basec);
        return -1;
+    }
 
     err = file_move(tmp_file_location, dest_file_name);