opkg: fix the crashing issue.
authorticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 15 Dec 2008 05:26:51 +0000 (05:26 +0000)
committerticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 15 Dec 2008 05:26:51 +0000 (05:26 +0000)
      It's a hanging pointer.
      Using installed_files without get and free

git-svn-id: http://opkg.googlecode.com/svn/trunk@144 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358

libopkg/pkg.c
libopkg/pkg_hash.c
libopkg/void_list.c

index 10427ed3bad4d0f7e66a2825f7fc4b582fa59f2e..d662664a362b119424aafe9fd6a4459b6e2ddda8 100644 (file)
@@ -1737,8 +1737,7 @@ int pkg_info_preinstall_check(opkg_conf_t *conf)
               // opkg_message(conf, OPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
               file_hash_set_file_owner(conf, installed_file, pkg);
          }
-         //FIXME: mark this line. Thid avoid crash, But the reference count shall be balanced. (If there are some delay after file_hash_set_file_owner, it wont crash (Pondering why?))
-         //pkg_free_installed_files(pkg);
+         pkg_free_installed_files(pkg);
      }
      pkg_vec_free(installed_pkgs);
 
index 97613e5c6ea5275ab4eed4a430647ae0d8789024..c63847b520f6e40005bad1a6b67532e2e3c66b90 100644 (file)
@@ -648,10 +648,13 @@ int file_hash_set_file_owner(opkg_conf_t *conf, const char *file_name, pkg_t *ow
      // opkg_message(conf, OPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
      hash_table_insert(file_hash, file_name, owning_pkg); 
      if (old_owning_pkg) {
+         pkg_get_installed_files(old_owning_pkg);
          str_list_remove_elt(old_owning_pkg->installed_files, file_name);
+         pkg_free_installed_files(old_owning_pkg);
          /* mark this package to have its filelist written */
          old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
          owning_pkg->state_flag |= SF_FILELIST_CHANGED;
+         
      }
      return 0;
 }
index f7490165b3399f5f2eb66143bf3191d114a1b716..8d61fbb1c8fbeae46eb3b65e10611d7020e2b6cb 100644 (file)
@@ -160,6 +160,15 @@ void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list
      void_list_elt_t *old_elt = NULL;
      void *old_data = NULL;
 
+     if (!list) {
+          fprintf(stderr, "Error: void_list_remove_elt list is NULL\n");
+          return NULL;
+     }
+     if (!target_data) {
+          fprintf(stderr, "Error: void_list_remove_elt target_data is NULL\n");
+         return NULL;
+     }
+
      /* first element */
      if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
          old_elt = list->head;