From 0e9c6932c4ecef14bc05533575d28772ff791490 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Fri, 23 Jun 2006 12:07:41 +0000 Subject: [PATCH] use malloc() + copy + free() instead of realloc() --- lib/syslib/safecopies.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/syslib/safecopies.c b/lib/syslib/safecopies.c index 01dff96e0..e88bf6531 100644 --- a/lib/syslib/safecopies.c +++ b/lib/syslib/safecopies.c @@ -66,19 +66,26 @@ cpf_grow(void) new_size = (1+ngrants)*2; assert(new_size > ngrants); - /* Grow block to new size. */ - if(!(new_grants=realloc(grants, new_size * sizeof(grants[0])))) + /* Allocate a block of new size. */ + if(!(new_grants=malloc(new_size * sizeof(grants[0])))) return; + /* Copy old block to new block. */ + if(grants && ngrants > 0) + memcpy(new_grants, grants, ngrants * sizeof(grants[0])); + /* Make sure new slots are marked unused (CPF_USED is clear). */ for(g = ngrants; g < new_size; g++) - grants[g].cp_flags = 0; + new_grants[g].cp_flags = 0; /* Inform kernel about new size (and possibly new location). */ - if(sys_privctl(SELF, SYS_PRIV_SET_GRANTS, new_size, new_grants)) + if(sys_privctl(SELF, SYS_PRIV_SET_GRANTS, new_size, new_grants)) { + free(new_grants); return; /* Failed - don't grow then. */ + } /* Update internal data. */ + if(grants && ngrants > 0) free(grants); grants = new_grants; ngrants = new_size; }