summaryrefslogtreecommitdiff
path: root/libarchive/archive_read_disk_set_standard_lookup.c
diff options
context:
space:
mode:
authorColin Percival <cperciva@daemonology.net>2011-08-16 00:30:48 -0400
committerColin Percival <cperciva@daemonology.net>2011-08-16 00:30:48 -0400
commita43875d305c005bebfbe78d1a2e2197ab39210e7 (patch)
tree9147f2ae85206f60a534ccb831607c65be08cc2c /libarchive/archive_read_disk_set_standard_lookup.c
parent7c0891cb751905119b36954e148850e6538ffd82 (diff)
downloadlibarchive-a43875d305c005bebfbe78d1a2e2197ab39210e7.tar.gz
Don't leak memory if realloc fails.
Via: Tarsnap SVN-Revision: 3612
Diffstat (limited to 'libarchive/archive_read_disk_set_standard_lookup.c')
-rw-r--r--libarchive/archive_read_disk_set_standard_lookup.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/libarchive/archive_read_disk_set_standard_lookup.c b/libarchive/archive_read_disk_set_standard_lookup.c
index 7e9a671c..3bc52c70 100644
--- a/libarchive/archive_read_disk_set_standard_lookup.c
+++ b/libarchive/archive_read_disk_set_standard_lookup.c
@@ -187,6 +187,8 @@ static const char *
lookup_uname_helper(struct name_cache *cache, id_t id)
{
struct passwd pwent, *result;
+ char * nbuff;
+ size_t nbuff_size;
int r;
if (cache->buff_size == 0) {
@@ -208,10 +210,12 @@ lookup_uname_helper(struct name_cache *cache, id_t id)
* we just double it and try again. Because the buffer
* is kept around in the cache object, we shouldn't
* have to do this very often. */
- cache->buff_size *= 2;
- cache->buff = realloc(cache->buff, cache->buff_size);
- if (cache->buff == NULL)
+ nbuff_size = cache->buff_size * 2;
+ nbuff = realloc(cache->buff, nbuff_size);
+ if (nbuff == NULL)
break;
+ cache->buff = nbuff;
+ cache->buff_size = nbuff_size;
}
if (r != 0) {
archive_set_error(cache->archive, errno,
@@ -251,6 +255,8 @@ static const char *
lookup_gname_helper(struct name_cache *cache, id_t id)
{
struct group grent, *result;
+ char * nbuff;
+ size_t nbuff_size;
int r;
if (cache->buff_size == 0) {
@@ -270,10 +276,12 @@ lookup_gname_helper(struct name_cache *cache, id_t id)
/* ERANGE means our buffer was too small, but POSIX
* doesn't tell us how big the buffer should be, so
* we just double it and try again. */
- cache->buff_size *= 2;
- cache->buff = realloc(cache->buff, cache->buff_size);
- if (cache->buff == NULL)
+ nbuff_size = cache->buff_size * 2;
+ nbuff = realloc(cache->buff, nbuff_size);
+ if (nbuff == NULL)
break;
+ cache->buff = nbuff;
+ cache->buff_size = nbuff_size;
}
if (r != 0) {
archive_set_error(cache->archive, errno,