From 51f839331913d9cb9f221ce36e4f18e9e7876e57 Mon Sep 17 00:00:00 2001 From: Jim Kingdon Date: Wed, 23 Mar 1994 00:34:44 +0000 Subject: [PATCH] * values.c (set_internalvar): Don't set var->value until we are sure there won't be an error(). --- gdb/ChangeLog | 3 +++ gdb/values.c | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4f138f5f558..f19074039f7 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,8 @@ Tue Mar 22 15:28:33 1994 Jim Kingdon (kingdon@lioth.cygnus.com) + * values.c (set_internalvar): Don't set var->value until we are + sure there won't be an error(). + * remote.c (get_offsets): Reinstate comment which was in remote_wait about use of SECT_OFF_TEXT and so on. diff --git a/gdb/values.c b/gdb/values.c index 11ed6f1296a..331a3e0dbd8 100644 --- a/gdb/values.c +++ b/gdb/values.c @@ -457,19 +457,31 @@ set_internalvar (var, val) struct internalvar *var; value_ptr val; { + value_ptr newval; + #ifdef IS_TRAPPED_INTERNALVAR if (IS_TRAPPED_INTERNALVAR (var->name)) SET_TRAPPED_INTERNALVAR (var, val, 0, 0, 0); #endif - free ((PTR)var->value); - var->value = value_copy (val); + newval = value_copy (val); + /* Force the value to be fetched from the target now, to avoid problems later when this internalvar is referenced and the target is gone or has changed. */ - if (VALUE_LAZY (var->value)) - value_fetch_lazy (var->value); - release_value (var->value); + if (VALUE_LAZY (newval)) + value_fetch_lazy (newval); + + /* Begin code which must not call error(). If var->value points to + something free'd, an error() obviously leaves a dangling pointer. + But we also get a danling pointer if var->value points to + something in the value chain (i.e., before release_value is + called), because after the error free_all_values will get called before + long. */ + free ((PTR)var->value); + var->value = newval; + release_value (newval); + /* End code which must not call error(). */ } char * -- 2.30.2