Skip to content

Commit ea8e029

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 872d651 commit ea8e029

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

sha1_file.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
18201820
{
18211821
int fd;
18221822
struct strbuf sb = STRBUF_INIT;
1823+
int rc = 0;
18231824

18241825
switch (st->st_mode & S_IFMT) {
18251826
case S_IFREG:
@@ -1836,16 +1837,15 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
18361837
if (!(flags & HASH_WRITE_OBJECT))
18371838
hash_sha1_file(sb.buf, sb.len, blob_type, oid->hash);
18381839
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);
18411841
strbuf_release(&sb);
18421842
break;
18431843
case S_IFDIR:
18441844
return resolve_gitlink_ref(path, "HEAD", oid->hash);
18451845
default:
18461846
return error("%s: unsupported file type", path);
18471847
}
1848-
return 0;
1848+
return rc;
18491849
}
18501850

18511851
int read_pack_header(int fd, struct pack_header *header)

0 commit comments

Comments
 (0)