Commit Diff


commit - 1c7e24f1803c43083e220e0e36c22555e478551d
commit + 97128b573c12726495716f9f6a31a57d4b1b06fd
blob - 392de87d05af9bbabbdd3ec0952ad4be427a5cfa
blob + 5321aeb6852951242235bd0d01906cd97ddf386f
--- lib/pack.c
+++ lib/pack.c
@@ -79,12 +79,15 @@ get_packfile_size(size_t *size, const char *path)
 	struct stat sb;
 	char *dot;
 
+	*size = 0;
+
 	dot = strrchr(path, '.');
 	if (dot == NULL)
 		return got_error(GOT_ERR_BAD_PATH);
 
 	/* Path must point to a pack index or to a pack file. */
 	if (strcmp(dot, ".idx") == 0) {
+		const struct got_error *err = NULL;
 		char *path_pack;
 		char base_path[PATH_MAX];
 
@@ -98,11 +101,11 @@ get_packfile_size(size_t *size, const char *path)
 		if (asprintf(&path_pack, "%s.pack", base_path) == -1)
 			return got_error_from_errno();
 
-		if (stat(path_pack, &sb) != 0) {
-			free(path_pack);
-			return got_error_from_errno();
-		}
+		if (stat(path_pack, &sb) != 0)
+			err = got_error_from_errno();
 		free(path_pack);
+		if (err)
+			return err;
 	} else if (strcmp(dot, ".pack") == 0) {
 		if (stat(path, &sb) != 0)
 			return got_error_from_errno();