sha1_file: release strbuf on error return in index_path()
strbuf_readlink() already frees the buffer for us on error. Clean up if write_sha1_file() fails as well instead of returning early. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Rene Scharfe committed
Aug 30, 2017 at 20:00 UTC
ea8e029785f87dc167491ebbc7ea3e924a72b5c4
1 file changed
+3
-3
sha1_file.c
+3
-3
@@ -1820,6 +1820,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
1820
{
1821
int fd;
1822
struct strbuf sb = STRBUF_INIT;
1823
+ int rc = 0;
1824
1825
switch (st->st_mode & S_IFMT) {
1826
case S_IFREG:
@@ -1836,8 +1837,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
1837
if (!(flags & HASH_WRITE_OBJECT))
1838
hash_sha1_file(sb.buf, sb.len, blob_type, oid->hash);
1839
else if (write_sha1_file(sb.buf, sb.len, blob_type, oid->hash))
1839
- return error("%s: failed to insert into database",
1840
- path);
1840
+ rc = error("%s: failed to insert into database", path);
1841
strbuf_release(&sb);
1842
break;
1843
case S_IFDIR:
@@ -1845,7 +1845,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
1845
default:
1846
return error("%s: unsupported file type", path);
1847
}
1848
- return 0;
1848
+ return rc;
1849
}
1850
1851
int read_pack_header(int fd, struct pack_header *header)