Fix a subtle leak.
[oweals/opkg-lede.git] / libopkg / opkg_download.c
index 0e6792763a04c03046b114d42e03be66ec001152..ab21ae9e182cce47a0205ab1f83fb4a6145aaac1 100644 (file)
@@ -117,7 +117,6 @@ int opkg_download(opkg_conf_t *conf, const char *src,
     }
 
 #ifdef HAVE_CURL
-    CURL *curl;
     CURLcode res;
     FILE * file = fopen (tmp_file_location, "w");
 
@@ -259,9 +258,8 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name
 {
      int err = 0;
      pkg_t *pkg;
+
      pkg = pkg_new();
-     if (pkg == NULL)
-         return ENOMEM;
 
      if (str_starts_with(url, "http://")
         || str_starts_with(url, "ftp://")) {
@@ -306,12 +304,9 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name
      pkg->state_want = SW_INSTALL;
      pkg->state_flag |= SF_PREFER;
      pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);  
-     if ( pkg == NULL ){
-        fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
-        return 0;
-     }
+
      if (namep) {
-         *namep = xstrdup(pkg->name);
+         *namep = pkg->name;
      }
      return 0;
 }
@@ -419,11 +414,13 @@ opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file)
         goto verify_file_end;
     }
 #if defined(HAVE_PATHFINDER)
-    if(!pkcs7_pathfinder_verify_signers(p7)){
-       opkg_message(conf,  OPKG_ERROR, "pkcs7_pathfinder_verify_signers: "
-               "Path verification failed\n");
+    if(conf->check_x509_path){
+       if(!pkcs7_pathfinder_verify_signers(p7)){
+           opkg_message(conf,  OPKG_ERROR, "pkcs7_pathfinder_verify_signers: "
+                   "Path verification failed\n");
+           goto verify_file_end;
+       }
     }
-
 #endif
 
     // Open the Package file to authenticate
@@ -609,13 +606,13 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data
            curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
        }else{
 #ifdef HAVE_PATHFINDER
-           if (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, curl_ssl_ctx_function) != CURLE_OK){
-               opkg_message(conf, OPKG_DEBUG, "Failed to set ssl path verification callback\n");
-           }else{
-               curl_easy_setopt(curl, CURLOPT_SSL_CTX_DATA, NULL);
+           if(conf->check_x509_path){
+               if (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, curl_ssl_ctx_function) != CURLE_OK){
+                   opkg_message(conf, OPKG_DEBUG, "Failed to set ssl path verification callback\n");
+               }else{
+                   curl_easy_setopt(curl, CURLOPT_SSL_CTX_DATA, NULL);
+               }
            }
-
-           //curl_easy_setopt(curl, CURLOPT_SSL_CERT_VERIFY_FUNCTION, curlcb_pathfinder);
 #endif
        }