[pacman-dev] [PATCH] Refactor do-while cycle in the api, util.c

Laszlo Papp djszapi at archlinux.us
Wed Nov 11 16:08:40 EST 2009


* It makes the code clearer to read/understand
* Cppcheck tool doesn't show this anymore: [./util.c:215]: (error) Resource leak: fd
---
 lib/libalpm/util.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index cf2d623..f54b2bf 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -212,8 +212,9 @@ int _alpm_lckmk()
 	_alpm_makepath(dir);
 	FREE(dir);

-	while((fd = open(file, O_WRONLY | O_CREAT | O_EXCL, 0000)) == -1
-			&& errno == EINTR);
+	do {
+		fd = open(file, O_WRONLY | O_CREAT | O_EXCL, 0000);
+	} while ( fd == -1 && errno == EINTR);
 	if(fd > 0) {
 		FILE *f = fdopen(fd, "w");
 		fprintf(f, "%ld\n", (long)getpid());
@@ -315,7 +316,7 @@ int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int

 		st = archive_entry_stat(entry);
 		entryname = archive_entry_pathname(entry);
-
+
 		if(S_ISREG(st->st_mode)) {
 			archive_entry_set_perm(entry, 0644);
 		} else if(S_ISDIR(st->st_mode)) {
--
1.6.5.1



More information about the pacman-dev mailing list