r4443 - in trunk/src/target/opkg: libopkg tests

thomas at docs.openmoko.org thomas at docs.openmoko.org
Tue May 20 20:23:56 CEST 2008


Author: thomas
Date: 2008-05-20 20:23:56 +0200 (Tue, 20 May 2008)
New Revision: 4443

Modified:
   trunk/src/target/opkg/libopkg/args.c
   trunk/src/target/opkg/libopkg/hash_table.c
   trunk/src/target/opkg/libopkg/opkg.c
   trunk/src/target/opkg/libopkg/opkg_conf.c
   trunk/src/target/opkg/libopkg/opkg_conf.h
   trunk/src/target/opkg/libopkg/opkg_download.c
   trunk/src/target/opkg/libopkg/opkg_install.c
   trunk/src/target/opkg/libopkg/opkg_remove.c
   trunk/src/target/opkg/libopkg/opkg_upgrade.c
   trunk/src/target/opkg/libopkg/pkg.c
   trunk/src/target/opkg/libopkg/pkg_hash.c
   trunk/src/target/opkg/libopkg/pkg_parse.c
   trunk/src/target/opkg/libopkg/pkg_vec.c
   trunk/src/target/opkg/tests/libopkg_test.c
Log:
opkg: (leak fixing, day 2) lots and lots of memory leaks fixed


Modified: trunk/src/target/opkg/libopkg/args.c
===================================================================
--- trunk/src/target/opkg/libopkg/args.c	2008-05-19 17:00:44 UTC (rev 4442)
+++ trunk/src/target/opkg/libopkg/args.c	2008-05-20 18:23:56 UTC (rev 4443)
@@ -83,6 +83,12 @@
 
 void args_deinit(args_t *args)
 {
+     free (args->offline_root);
+     free (args->offline_root_pre_script_cmd);
+     free (args->offline_root_post_script_cmd);
+
+     free (args->dest);
+     free (args->tmp_dir);
      free(args->conf_file);
      args->conf_file = NULL;
 }

Modified: trunk/src/target/opkg/libopkg/hash_table.c
===================================================================
--- trunk/src/target/opkg/libopkg/hash_table.c	2008-05-19 17:00:44 UTC (rev 4442)
+++ trunk/src/target/opkg/libopkg/hash_table.c	2008-05-20 18:23:56 UTC (rev 4443)
@@ -85,6 +85,7 @@
     /* free the reminaing entries */
     for (i = 0; i < hash->n_entries; i++) {
 	hash_entry_t *hash_entry = (hash->entries + i);
+	free (hash_entry->key);
 	/* skip the first entry as this is part of the array */
 	hash_entry = hash_entry->next;
         while (hash_entry)

Modified: trunk/src/target/opkg/libopkg/opkg.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.c	2008-05-19 17:00:44 UTC (rev 4442)
+++ trunk/src/target/opkg/libopkg/opkg.c	2008-05-20 18:23:56 UTC (rev 4443)
@@ -175,6 +175,7 @@
   free (p->description);
   free (p->tags);
   free (p->url);
+  free (p->repository);
 
   free (p);
 }
@@ -202,6 +203,10 @@
 
   opkg_conf_deinit (opkg->conf);
   args_deinit (opkg->args);
+  free (opkg->options);
+  free (opkg->args);
+  free (opkg->conf);
+  free (opkg);
 }
 
 int
@@ -359,7 +364,7 @@
 opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
 {
   int err;
-  char *package_id = NULL, *stripped_filename;
+  char *stripped_filename;
   opkg_progress_data_t pdata;
   pkg_t *old, *new;
   pkg_vec_t *deps, *all;
@@ -470,9 +475,6 @@
   pdata.action = OPKG_INSTALL;
   progress (pdata, 75);
 
-  if (!package_id)
-    package_id = strdup (package_name);
-
   /* unpack the package */
   err = opkg_install_pkg(opkg->conf, new, 0);
 
@@ -658,6 +660,7 @@
   pkg_src_t *src;
   int sources_list_count, sources_done;
   opkg_progress_data_t pdata;
+  char *tmp_file_name = NULL;
 
   opkg_assert (opkg != NULL);
 
@@ -723,7 +726,6 @@
     sprintf_alloc (&list_file_name, "%s/%s", lists_dir, src->name);
     if (src->gzip)
     {
-      char *tmp_file_name;
       FILE *in, *out;
       struct _curl_cb_data cb_data;
 
@@ -758,6 +760,7 @@
     }
     else
       err = opkg_download (opkg->conf, url, list_file_name, NULL, NULL);
+    free (tmp_file_name);
 
     if (err)
     {
@@ -776,8 +779,6 @@
       sprintf_alloc (&url, "%s/%s", src->value, "Packages.sig");
 
     /* create temporary file for it */
-    char *tmp_file_name;
-
     sprintf_alloc (&tmp_file_name, "%s/%s", tmp, "Packages.sig");
 
     err = opkg_download (opkg->conf, url, tmp_file_name, NULL, NULL);

Modified: trunk/src/target/opkg/libopkg/opkg_conf.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg_conf.c	2008-05-19 17:00:44 UTC (rev 4442)
+++ trunk/src/target/opkg/libopkg/opkg_conf.c	2008-05-20 18:23:56 UTC (rev 4443)
@@ -330,6 +330,7 @@
 
      free(conf->tmp_dir); /*XXX*/
      free(conf->lists_dir);
+     free(conf->pending_dir);
 
      pkg_src_list_deinit(&conf->pkg_src_list);
      pkg_dest_list_deinit(&conf->pkg_dest_list);
@@ -578,7 +579,7 @@
 		    opkg_message(conf, OPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
 		    value = strdup("10");
 	       }
-	       nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
+	       nv_pair_list_append(&conf->arch_list, name, value);
 	  } else {
 	       fprintf(stderr, "WARNING: Ignoring unknown configuration "
 		       "parameter: %s %s %s\n", type, name, value);

Modified: trunk/src/target/opkg/libopkg/opkg_conf.h
===================================================================
--- trunk/src/target/opkg/libopkg/opkg_conf.h	2008-05-19 17:00:44 UTC (rev 4442)
+++ trunk/src/target/opkg/libopkg/opkg_conf.h	2008-05-20 18:23:56 UTC (rev 4443)
@@ -50,7 +50,7 @@
 
      char *tmp_dir;
      char *lists_dir;
-     const char *pending_dir;
+     char *pending_dir;
 
      /* options */
      int autoremove;

Modified: trunk/src/target/opkg/libopkg/opkg_download.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg_download.c	2008-05-19 17:00:44 UTC (rev 4442)
+++ trunk/src/target/opkg/libopkg/opkg_download.c	2008-05-20 18:23:56 UTC (rev 4443)
@@ -99,19 +99,26 @@
 	    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);
 

Modified: trunk/src/target/opkg/libopkg/opkg_install.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg_install.c	2008-05-19 17:00:44 UTC (rev 4442)
+++ trunk/src/target/opkg/libopkg/opkg_install.c	2008-05-20 18:23:56 UTC (rev 4443)
@@ -394,6 +394,7 @@
      }
 
      if (ndepends <= 0) {
+	  pkg_vec_free(depends);
 	  return 0;
      }
 
@@ -966,7 +967,7 @@
 	       signal(SIGINT, old_handler);
 	  else
 	       sigprocmask(SIG_UNBLOCK, &newset, &oldset);
-
+          pkg_vec_free (replacees);
 	  return 0;
      
 
@@ -996,6 +997,7 @@
 	  else
 	       sigprocmask(SIG_UNBLOCK, &newset, &oldset);
 
+          pkg_vec_free (replacees);
 	  return err;
      }
      opkg_set_current_state (conf, OPKG_STATE_NONE, NULL);

Modified: trunk/src/target/opkg/libopkg/opkg_remove.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg_remove.c	2008-05-19 17:00:44 UTC (rev 4442)
+++ trunk/src/target/opkg/libopkg/opkg_remove.c	2008-05-20 18:23:56 UTC (rev 4443)
@@ -271,6 +271,8 @@
 	       free(dependents);
 	       if (err) return err;
 	  }
+          if (dependents)
+              free(dependents);
      }
 
      if ( message==0 ){

Modified: trunk/src/target/opkg/libopkg/opkg_upgrade.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg_upgrade.c	2008-05-19 17:00:44 UTC (rev 4442)
+++ trunk/src/target/opkg/libopkg/opkg_upgrade.c	2008-05-20 18:23:56 UTC (rev 4443)
@@ -72,6 +72,8 @@
           old->state_want = SW_DEINSTALL;
      }
 
+    free(old_version);
+    free(new_version);
      new->state_flag |= SF_USER;
      return opkg_install_pkg(conf, new,1);
 }

Modified: trunk/src/target/opkg/libopkg/pkg.c
===================================================================
--- trunk/src/target/opkg/libopkg/pkg.c	2008-05-19 17:00:44 UTC (rev 4442)
+++ trunk/src/target/opkg/libopkg/pkg.c	2008-05-20 18:23:56 UTC (rev 4443)
@@ -142,6 +142,19 @@
      return 0;
 }
 
+void compound_depend_deinit (compound_depend_t *depends)
+{
+    int i;
+    for (i = 0; i < depends->possibility_count; i++)
+    {
+        depend_t *d;
+        d = depends->possibilities[i];
+        free (d->version);
+        free (d);
+    }
+    free (depends->possibilities);
+}
+
 void pkg_deinit(pkg_t *pkg)
 {
      int i;
@@ -171,59 +184,59 @@
      pkg->state_flag = SF_OK;
      pkg->state_status = SS_NOT_INSTALLED;
 
+     //for (i = 0; i < pkg->replaces_count; i++)
+     free (pkg->replaces);
+     pkg->replaces = NULL;
+
      for (i = 0; i < pkg->depends_count; i++)
        free (pkg->depends_str[i]);
      free(pkg->depends_str);
      pkg->depends_str = NULL;
-     pkg->depends_count = 0;
 
      for (i = 0; i < pkg->provides_count; i++)
        free (pkg->provides_str[i]);
      free(pkg->provides_str);
      pkg->provides_str = NULL;
-     pkg->provides_count = 0;
 
      for (i = 0; i < pkg->conflicts_count; i++)
        free (pkg->conflicts_str[i]);
      free(pkg->conflicts_str);
      pkg->conflicts_str = NULL;
-     pkg->conflicts_count = 0;
 
      for (i = 0; i < pkg->replaces_count; i++)
        free (pkg->replaces_str[i]);
      free(pkg->replaces_str);
      pkg->replaces_str = NULL;
-     pkg->replaces_count = 0;
 
      for (i = 0; i < pkg->recommends_count; i++)
        free (pkg->recommends_str[i]);
      free(pkg->recommends_str);
      pkg->recommends_str = NULL;
-     pkg->recommends_count = 0;
 
+     for (i = 0; i < pkg->suggests_count; i++)
+       free (pkg->suggests_str[i]);
+     free(pkg->suggests_str);
+     pkg->suggests_str = NULL;
+
      if (pkg->depends)
      {
        int count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
        int x;
 
        for (x = 0; x < count; x++)
-       {
-         compound_depend_t *depends;
-	 depends = &pkg->depends[x];
-
-         for (i = 0; i < depends->possibility_count; i++)
-         {
-           depend_t *d;
-           d = depends->possibilities[i];
-           free (d->version);
-           free (d);
-	 }
-	 free (depends->possibilities);
-       }
+	 compound_depend_deinit (&pkg->depends[x]);
        free (pkg->depends);
      }
+
+     if (pkg->conflicts)
+     {
+       int x;
+       for (x = 0; x < pkg->conflicts_count; x++)
+         compound_depend_deinit (&pkg->conflicts[x]);
+       free (pkg->conflicts);
+     }
+
      free (pkg->provides);
-     free (pkg->conflicts);
 
      pkg->pre_depends_count = 0;
      free(pkg->pre_depends_str);
@@ -1398,6 +1411,7 @@
 	  }
 
 	  str_list_deinit(pkg->installed_files);
+	  free (pkg->installed_files);
      }
 
      pkg->installed_files = NULL;
@@ -1800,5 +1814,6 @@
 		    opkg_message(conf, OPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
 	  }
      }
+     pkg_vec_free (installed_pkgs);
      return 0;
 }

Modified: trunk/src/target/opkg/libopkg/pkg_hash.c
===================================================================
--- trunk/src/target/opkg/libopkg/pkg_hash.c	2008-05-19 17:00:44 UTC (rev 4442)
+++ trunk/src/target/opkg/libopkg/pkg_hash.c	2008-05-20 18:23:56 UTC (rev 4443)
@@ -73,7 +73,9 @@
   }
 
   abstract_pkg_vec_free (ab_pkg->provided_by);
+  abstract_pkg_vec_free (ab_pkg->replaced_by);
   pkg_vec_free (ab_pkg->pkgs);
+  free (ab_pkg->depended_upon_by);
   free (ab_pkg->name);
   free (ab_pkg);
 }

Modified: trunk/src/target/opkg/libopkg/pkg_parse.c
===================================================================
--- trunk/src/target/opkg/libopkg/pkg_parse.c	2008-05-19 17:00:44 UTC (rev 4442)
+++ trunk/src/target/opkg/libopkg/pkg_parse.c	2008-05-20 18:23:56 UTC (rev 4443)
@@ -140,12 +140,15 @@
   pkg->revision = "";
   pkg->familiar_revision = "";
 
+  if (!pkg->version)
+  {
   pkg->version= malloc(strlen(raw)+1);
   if ( pkg->version == NULL ) {
      fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
      return ENOMEM;
   }
   strcpy(pkg->version, raw);
+  }
 
   hyphen= strrchr(pkg->version,'-');
 
@@ -304,6 +307,7 @@
 	    else if(isGenericFieldType("Installed-Time:", *lines)) {
 		char *time_str = parseGenericFieldType("Installed-Time", *lines);
 		pkg->installed_time = strtoul(time_str, NULL, 0);
+		free (time_str);
 	    }	    
 	    break;
 
@@ -376,7 +380,11 @@
     *raw = lines;
 /* If the ipk has not a Provides line, we insert our false line */ 
     if ( pkg_false_provides==1)
-       pkg->provides_str = parseDependsString ((char *)"Provides: opkg_internal_use_only ", &pkg->provides_count);
+    {
+       pkg->provides_count = 1;
+       pkg->provides_str = malloc (sizeof (char*));
+       pkg->provides_str[0] = strdup ("opkg_internal_use_only");
+    }
 
     if (pkg->name) {
 	return 0;

Modified: trunk/src/target/opkg/libopkg/pkg_vec.c
===================================================================
--- trunk/src/target/opkg/libopkg/pkg_vec.c	2008-05-19 17:00:44 UTC (rev 4442)
+++ trunk/src/target/opkg/libopkg/pkg_vec.c	2008-05-20 18:23:56 UTC (rev 4443)
@@ -185,6 +185,8 @@
 
 void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
 {
+    if (!vec)
+      return;
     free(vec->pkgs);
     free(vec);
 }

Modified: trunk/src/target/opkg/tests/libopkg_test.c
===================================================================
--- trunk/src/target/opkg/tests/libopkg_test.c	2008-05-19 17:00:44 UTC (rev 4442)
+++ trunk/src/target/opkg/tests/libopkg_test.c	2008-05-20 18:23:56 UTC (rev 4443)
@@ -38,6 +38,7 @@
 package_list_upgradable_callback (opkg_t *opkg, opkg_package_t *pkg, void *data)
 {
   printf ("%s - %s\n", pkg->name, pkg->version);
+  opkg_package_free (pkg);
 }
 
 void
@@ -91,11 +92,11 @@
     if (pkg)
     {
       print_package (pkg);
-      opkg_package_free (find_pkg);
       opkg_package_free (pkg);
     }
     else
       printf ("Package \"%s\" not found!\n", find_pkg->name);
+    opkg_package_free (find_pkg);
   }
   else
     printf ("No package available to test find_package.\n");





More information about the commitlog mailing list