opkg: fix some memory leak and double free issues.
authorticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 15 Dec 2008 05:25:48 +0000 (05:25 +0000)
committerticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 15 Dec 2008 05:25:48 +0000 (05:25 +0000)
git-svn-id: http://opkg.googlecode.com/svn/trunk@139 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358

libopkg/opkg_cmd.c
libopkg/opkg_remove.c

index 6eb01eb3638e8799bad08e96a8aa57aa217d20e5..fcf74f6910026b4930e82a272cfbbd1ebdad0a85 100644 (file)
@@ -909,9 +909,9 @@ static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv)
 
     done = 0;
 
-     available = pkg_vec_alloc();
      pkg_info_preinstall_check(conf);
      if ( argc > 0 ) {
+        available = pkg_vec_alloc();
         pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
         for (i=0; i < argc; i++) {
            pkg_name = malloc(strlen(argv[i])+2);
index c8cfb5524f7202c54af29bb2a08bd61870d01e72..1debf21416f0bf6e3f3a0bd93b5227cde49fc5be 100644 (file)
@@ -90,7 +90,7 @@ int opkg_remove_dependent_pkgs (opkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **
     int i;
     int a;
     int count;
-    pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
+    pkg_vec_t *dependent_pkgs;
     abstract_pkg_t * ab_pkg;
 
     if((ab_pkg = pkg->parent) == NULL){
@@ -110,6 +110,8 @@ int opkg_remove_dependent_pkgs (opkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **
 
     i = 0;
     count = 1;
+    dependent_pkgs = pkg_vec_alloc();
+
     while (dependents [i] != NULL) {
         abstract_pkg_t *dep_ab_pkg = dependents[i];
        
@@ -131,16 +133,20 @@ int opkg_remove_dependent_pkgs (opkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **
         * 2 - to keep track of pkgs whose deps have been checked alrdy  - Karthik */   
     }
     
-    if (count == 1)
-           return 0;
+    if (count == 1) {
+        free(dependent_pkgs);  
+       return 0;
+    }
     
     
+    int err=0;
     for (i = 0; i < dependent_pkgs->len; i++) {
-        int err = opkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
+        err = opkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
         if (err)
-            return err;
+            break;
     }
-    return 0;
+    free(dependent_pkgs);
+    return err;
 }
 
 static int user_prefers_removing_dependents(opkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
@@ -268,8 +274,10 @@ int opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg,int message)
 
               /* remove packages depending on this package - Karthik */
               err = opkg_remove_dependent_pkgs (conf, pkg, dependents);
-              free(dependents);
-              if (err) return err;
+              if (err) {
+                free(dependents);
+                 return err;
+               }
          }
           if (dependents)
               free(dependents);