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>
This commit is contained in:
Rene Scharfe 2017-08-30 20:00:29 +02:00 committed by Junio C Hamano
parent 872d651f52
commit ea8e029785

View File

@ -1820,6 +1820,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
{ {
int fd; int fd;
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;
int rc = 0;
switch (st->st_mode & S_IFMT) { switch (st->st_mode & S_IFMT) {
case S_IFREG: case S_IFREG:
@ -1836,8 +1837,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
if (!(flags & HASH_WRITE_OBJECT)) if (!(flags & HASH_WRITE_OBJECT))
hash_sha1_file(sb.buf, sb.len, blob_type, oid->hash); hash_sha1_file(sb.buf, sb.len, blob_type, oid->hash);
else if (write_sha1_file(sb.buf, sb.len, blob_type, oid->hash)) else if (write_sha1_file(sb.buf, sb.len, blob_type, oid->hash))
return error("%s: failed to insert into database", rc = error("%s: failed to insert into database", path);
path);
strbuf_release(&sb); strbuf_release(&sb);
break; break;
case S_IFDIR: case S_IFDIR:
@ -1845,7 +1845,7 @@ int index_path(struct object_id *oid, const char *path, struct stat *st, unsigne
default: default:
return error("%s: unsupported file type", path); return error("%s: unsupported file type", path);
} }
return 0; return rc;
} }
int read_pack_header(int fd, struct pack_header *header) int read_pack_header(int fd, struct pack_header *header)