diff options
author | graham.gower@gmail.com <graham.gower@gmail.com@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2010-09-20 21:25:04 (EDT) |
---|---|---|
committer | graham.gower@gmail.com <graham.gower@gmail.com@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2010-09-20 21:25:04 (EDT) |
commit | a12def2ef9f33f024b5cda7f48fc794f48315a5d (patch) | |
tree | cbc3b9833e7f60605ae9ccc36991706361633ef2 | |
parent | b501406f5cd2f475b1f76ea02c42f3d530302bbe (diff) |
A proper fix this time. From Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>.
git-svn-id: http://opkg.googlecode.com/svn/trunk@573 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
-rw-r--r-- | libopkg/file_util.c | 5 | ||||
-rw-r--r-- | libopkg/opkg_conf.c | 38 |
2 files changed, 32 insertions, 11 deletions
diff --git a/libopkg/file_util.c b/libopkg/file_util.c index cf5f774..897546e 100644 --- a/libopkg/file_util.c +++ b/libopkg/file_util.c @@ -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); diff --git a/libopkg/opkg_conf.c b/libopkg/opkg_conf.c index 22c99eb..9c1ed34 100644 --- a/libopkg/opkg_conf.c +++ b/libopkg/opkg_conf.c @@ -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); + } } |