From: Pedro Alves Date: Mon, 8 Sep 2008 21:16:18 +0000 (+0000) Subject: * regcache.c (new_register_cache): Return NULL if the register X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5822d809e73ed680e384213620a148b2e86c3b13;p=binutils-gdb.git * regcache.c (new_register_cache): Return NULL if the register cache size isn't known yet. (free_register_cache): Avoid dereferencing a NULL regcache. --- diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index b84dc01e0cc..0b5d10b551e 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,9 @@ +2008-09-08 Pedro Alves + + * regcache.c (new_register_cache): Return NULL if the register + cache size isn't known yet. + (free_register_cache): Avoid dereferencing a NULL regcache. + 2008-09-04 Daniel Jacobowitz * configure.srv: Merge MIPS and MIPS64. diff --git a/gdb/gdbserver/regcache.c b/gdb/gdbserver/regcache.c index a324d43df65..b5ec2159fc2 100644 --- a/gdb/gdbserver/regcache.c +++ b/gdb/gdbserver/regcache.c @@ -91,6 +91,9 @@ new_register_cache (void) { struct inferior_regcache_data *regcache; + if (register_bytes == 0) + return NULL; /* The architecture hasn't been initialized yet. */ + regcache = malloc (sizeof (*regcache)); /* Make sure to zero-initialize the register cache when it is created, @@ -111,8 +114,11 @@ free_register_cache (void *regcache_p) struct inferior_regcache_data *regcache = (struct inferior_regcache_data *) regcache_p; - free (regcache->registers); - free (regcache); + if (regcache) + { + free (regcache->registers); + free (regcache); + } } static void