A proper fix this time. From Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>.
authorgraham.gower@gmail.com <graham.gower@gmail.com@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Tue, 21 Sep 2010 01:25:04 +0000 (01:25 +0000)
committergraham.gower@gmail.com <graham.gower@gmail.com@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Tue, 21 Sep 2010 01:25:04 +0000 (01:25 +0000)
git-svn-id: http://opkg.googlecode.com/svn/trunk@573 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358

libopkg/file_util.c
libopkg/opkg_conf.c

index cf5f7740e2bed43896575bde18d91fe15ccbb688..897546e838d4d8298ddb94a2546fdbfb283371fb 100644 (file)
@@ -238,6 +238,11 @@ rm_r(const char *path)
        DIR *dir;
        struct dirent *dent;
 
+       if (path == NULL) {
+               opkg_perror(ERROR, "Missing directory parameter");
+               return -1;
+       }
+
        dir = opendir(path);
        if (dir == NULL) {
                opkg_perror(ERROR, "Failed to open dir %s", path);
index 22c99ebde86c2ce2d563a3f7a9eb830c7ab73744..9c1ed34f2aea26e3a432470bde84d3483ccac5ae 100644 (file)
@@ -484,6 +484,11 @@ opkg_conf_load(void)
        else
                sprintf_alloc (&lock_file, "%s", OPKGLOCKFILE);
 
+       if (lock_file == NULL) {
+               opkg_perror(ERROR, "Could not allocate memory for lock file name");
+               goto err2;
+       }
+
        lock_fd = creat(lock_file, S_IRUSR | S_IWUSR | S_IRGRP);
        if (lock_fd == -1) {
                opkg_perror(ERROR, "Could not create lock file %s", lock_file);
@@ -495,6 +500,7 @@ opkg_conf_load(void)
                if (close(lock_fd) == -1)
                        opkg_perror(ERROR, "Couldn't close descriptor %d (%s)",
                                lock_fd, lock_file);
+               lock_fd = -1;
                goto err2;
        }
 
@@ -568,7 +574,10 @@ err3:
        if (unlink(lock_file) == -1)
                opkg_perror(ERROR, "Couldn't unlink %s", lock_file);
 err2:
-       free(lock_file);
+       if (lock_file) {
+               free(lock_file);
+               lock_file = NULL;
+       }
 err1:
        pkg_src_list_deinit(&conf->pkg_src_list);
        pkg_dest_list_deinit(&conf->pkg_dest_list);
@@ -599,9 +608,11 @@ opkg_conf_deinit(void)
        int i;
        char **tmp;
 
-       rm_r(conf->tmp_dir);
+       if (conf->tmp_dir)
+               rm_r(conf->tmp_dir);
 
-       free(conf->lists_dir);
+       if (conf->lists_dir)
+               free(conf->lists_dir);
 
        if (conf->dest_str)
                free(conf->dest_str);
@@ -633,15 +644,20 @@ opkg_conf_deinit(void)
        hash_table_deinit(&conf->file_hash);
        hash_table_deinit(&conf->obs_file_hash);
 
-       if (lockf(lock_fd, F_ULOCK, (off_t)0) == -1)
-               opkg_perror(ERROR, "Couldn't unlock %s", lock_file);
+       if (lock_fd != -1) {
+               if (lockf(lock_fd, F_ULOCK, (off_t)0) == -1)
+                       opkg_perror(ERROR, "Couldn't unlock %s", lock_file);
 
-       if (close(lock_fd) == -1)
-               opkg_perror(ERROR, "Couldn't close descriptor %d (%s)",
-                               lock_fd, lock_file);
+               if (close(lock_fd) == -1)
+                       opkg_perror(ERROR, "Couldn't close descriptor %d (%s)",
+                                       lock_fd, lock_file);
 
-       if (unlink(lock_file) == -1)
-               opkg_perror(ERROR, "Couldn't unlink %s", lock_file);
+       }
 
-       free(lock_file);
+       if (lock_file) {
+               if (unlink(lock_file) == -1)
+                       opkg_perror(ERROR, "Couldn't unlink %s", lock_file);
+
+               free(lock_file);
+       }
 }