Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Modules on HP-UX (Re: D07multibyte.ztst failure on HP-UX 11.11)



On Fri, 08 May 2009 08:41:23 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> [off-list]
> 
> On May 8,  3:29pm, Peter Stephenson wrote:
> } Subject: Re: Modules on HP-UX (Re: D07multibyte.ztst failure on HP-UX 11.1
> }
> } Looks to me like some basic memory corruption:  is it worth running
> } valgrind?
> 
> (skipping stuff up to the point of actual error)
>...
> ==17685==    at 0x8127AA0: zle_set_highlight (zle_refresh.c:354)

There are lots of these, but all seem to boil down to the fact that
region_highlights and n_region_highlights are not set to zero when the
module is unloaded and the same values are used when the module is loaded
again.

It seemed like this was worth a note in the development guide.  The main
problem is no one reads that.

Index: Etc/zsh-development-guide
===================================================================
RCS file: /cvsroot/zsh/zsh/Etc/zsh-development-guide,v
retrieving revision 1.21
diff -u -r1.21 zsh-development-guide
--- Etc/zsh-development-guide	22 Jan 2009 12:12:14 -0000	1.21
+++ Etc/zsh-development-guide	11 May 2009 08:51:11 -0000
@@ -279,6 +279,10 @@
 not rely on the module successfully being set up.
 The state from `finish_' module is currently ignored; it is called
 too late to prevent the module from being unloaded.
+*Note* in addition to freeing memory, variables associated with allocated
+memory should be set to NULL or to indicate arrays are empty, etc.  It
+should not be assumed that the variables will automatically be zeroed if
+the module is reloaded (though some configurations may do this).
 
 In short, the `cleanup_'-function should undo what the `boot_'-function did
 (together with handling any residual effects of `enables_'), but should
Index: Src/Zle/zle_refresh.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_refresh.c,v
retrieving revision 1.75
diff -u -r1.75 zle_refresh.c
--- Src/Zle/zle_refresh.c	8 May 2009 08:37:31 -0000	1.75
+++ Src/Zle/zle_refresh.c	11 May 2009 08:51:11 -0000
@@ -2644,6 +2644,10 @@
     freevideo();
 
     if (region_highlights)
+    {
 	zfree(region_highlights,
 	      sizeof(struct region_highlight) * n_region_highlights);
+	region_highlights = NULL;
+	n_region_highlights = 0;
+    }
 }


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author