commit:dead5bdc521b34c85256737b616f4072a78dc2fb
author:Chip Black
committer:Chip Black
date:Mon Feb 21 15:35:29 2011 -0600
parents:efabc7da2c7dff11ab6835d23655a023f1cbc296
Further error handling refinement
diff --git a/database/tags.c b/database/tags.c
line changes: +2/-6
index 5b3b3ce..5ec12fa
--- a/database/tags.c
+++ b/database/tags.c
@@ -122,13 +122,11 @@ struct tag * tag_list(const char *tag, uint64_t offset, int *count, int directio
 	int tag_fd = open(filename, O_RDONLY, 0600);
 	if (tag_fd == -1) {
 		perror("Could not open tag file");
-		*count = 0;
-		return NULL;
+		goto tag_list_open_failed;
 	}
 
 	fstat(tag_fd, &st);
 	if (st.st_size == 0) {
-		*count = 0;
 		goto tag_list_map_failed;
 	}
 	n_tag_records = st.st_size / sizeof(struct tag);
@@ -136,20 +134,17 @@ struct tag * tag_list(const char *tag, uint64_t offset, int *count, int directio
 		*count = n_tag_records - offset;
 	if (offset > n_tag_records) {
 		fprintf(stderr, "Cannot access tag record beyond end\n");
-		*count = 0;
 		goto tag_list_map_failed;
 	}
 
 	taglist = (struct tag *) mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, tag_fd, 0);
 	if (taglist == MAP_FAILED) {
 		perror("Could not mmap tag file");
-		*count = 0;
 		goto tag_list_map_failed;
 	}
 	retlist = (struct tag *) malloc(sizeof(struct tag) * *count);
 	if (retlist == NULL) {
 		perror("Could not allocate memory for tag list");
-		*count = 0;
 		goto tag_list_malloc_failed;
 	}
 	switch(direction) {
@@ -170,6 +165,7 @@ tag_list_malloc_failed:
 tag_list_map_failed:
 	close(tag_fd);
 tag_list_open_failed:
+	*count = 0;
 	return NULL;
 }