Remove dead code, sprintf_alloc() cannot fail. Opkg will exit instead.
[oweals/opkg-lede.git] / libopkg / opkg_conf.c
index 22c99ebde86c2ce2d563a3f7a9eb830c7ab73744..acac1b49894d7e92b1baf2f6aaf283460f9d3cc7 100644 (file)
@@ -495,6 +495,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 +569,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 +603,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 +639,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);
+       }
 }