dedup

deduplicating backup program
git clone git://git.2f30.org/dedup
Log | Files | Refs | README | LICENSE

commit 88a8835e3138a285503a2a93454daa1220caa490
parent 0c04bdbe93b0bda78e8122d1a4a418f6f2fa7ad2
Author: sin <sin@2f30.org>
Date:   Sun,  5 May 2019 20:27:39 +0100

Fix memleak

Diffstat:
Mbstorage.c | 13++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/bstorage.c b/bstorage.c @@ -708,17 +708,18 @@ bscheck(struct bctx *bctx, unsigned char *md) return -1; } - if (lseek(sctx->fd, bd->offset, SEEK_SET) < 0) { - bseterr("lseek: %s", strerror(errno)); - return -1; - } - buf = malloc(bd->size); if (buf == NULL) { bseterr("malloc: %s", strerror(errno)); return -1; } + if (lseek(sctx->fd, bd->offset, SEEK_SET) < 0) { + free(buf); + bseterr("lseek: %s", strerror(errno)); + return -1; + } + if (xread(sctx->fd, buf, bd->size) != bd->size) { free(buf); bseterr("failed to read block: %s", strerror(errno)); @@ -732,9 +733,11 @@ bscheck(struct bctx *bctx, unsigned char *md) } if (memcmp(key.md, md, MDSIZE) != 0) { + free(buf); bseterr("block mismatch"); return -1; } + free(buf); return 0; }