summaryrefslogtreecommitdiff
path: root/libarchive/archive_match.c
diff options
context:
space:
mode:
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>2012-09-18 20:14:18 +0900
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>2012-09-18 20:14:18 +0900
commit0ddb050474551e3a4888fa865879a6ed2c39893b (patch)
tree439cc7d706551384ef57a74ed23e1bdf04fba038 /libarchive/archive_match.c
parent52ca91f512995676c9f811583751d0bd48cbef43 (diff)
downloadlibarchive-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_match.c')
-rw-r--r--libarchive/archive_match.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/libarchive/archive_match.c b/libarchive/archive_match.c
index 6b533e6b..6170dc53 100644
--- a/libarchive/archive_match.c
+++ b/libarchive/archive_match.c
@@ -1675,13 +1675,16 @@ add_owner_id(struct archive_match *a, struct id_array *ids, int64_t id)
unsigned i;
if (ids->count + 1 >= ids->size) {
+ void *p;
+
if (ids->size == 0)
ids->size = 8;
else
ids->size *= 2;
- ids->ids = realloc(ids->ids, sizeof(*ids->ids) * ids->size);
- if (ids->ids == NULL)
+ p = realloc(ids->ids, sizeof(*ids->ids) * ids->size);
+ if (p == NULL)
return (error_nomem(a));
+ ids->ids = (int64_t *)p;
}
/* Find an insert point. */