diff options
author | Michihiro NAKAJIMA <ggcueroad@gmail.com> | 2012-09-18 20:14:18 +0900 |
---|---|---|
committer | Michihiro NAKAJIMA <ggcueroad@gmail.com> | 2012-09-18 20:14:18 +0900 |
commit | 0ddb050474551e3a4888fa865879a6ed2c39893b (patch) | |
tree | 439cc7d706551384ef57a74ed23e1bdf04fba038 /libarchive/archive_write_set_format_iso9660.c | |
parent | 52ca91f512995676c9f811583751d0bd48cbef43 (diff) | |
download | libarchive-0ddb050474551e3a4888fa865879a6ed2c39893b.tar.gz |
Fix a possibility of memory leaks when realloc fails.
Do not assign the return value of realloc into the variable that has
the original pointer because if realloc failed we will lose the chance
to release the address.
Diffstat (limited to 'libarchive/archive_write_set_format_iso9660.c')
-rw-r--r-- | libarchive/archive_write_set_format_iso9660.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/libarchive/archive_write_set_format_iso9660.c b/libarchive/archive_write_set_format_iso9660.c index 483de908..c6a4c2d5 100644 --- a/libarchive/archive_write_set_format_iso9660.c +++ b/libarchive/archive_write_set_format_iso9660.c @@ -5818,17 +5818,18 @@ idr_ensure_poolsize(struct archive_write *a, struct idr *idr, { if (idr->pool_size < cnt) { + void *p; const int bk = (1 << 7) - 1; int psize; psize = (cnt + bk) & ~bk; - idr->idrent_pool = realloc(idr->idrent_pool, - sizeof(struct idrent) * psize); - if (idr->idrent_pool == NULL) { + p = realloc(idr->idrent_pool, sizeof(struct idrent) * psize); + if (p == NULL) { archive_set_error(&a->archive, ENOMEM, "Can't allocate memory"); return (ARCHIVE_FATAL); } + idr->idrent_pool = (struct idrent *)p; idr->pool_size = psize; } return (ARCHIVE_OK); |