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

Bad frees in bindkey code



I've been getting some messages about freeing already free storage
from bindkey's with multiple lead-in characters, which this purports
to fix.   I think I've found all the places a key's str component is
freed and set it to zero.  (I could have checked for z_sendstring at
the second free instead, but it seems neater to make sure the pointer
is null anyway.)

(And greetings from eastern Germany, too.)

*** Src/zle_main.c.free	Tue Oct 10 01:26:42 1995
--- Src/zle_main.c	Tue Oct 17 09:44:34 1995
***************
*** 924,931 ****
  			free(keybindtab->removenode(keybindtab, s));
  		} else {
  		    if (ky && ky->prefixct) {
! 			if (ky->func == z_sendstring)
  			    zfree(ky->str, ky->len);
  			ky->func = z_undefinedkey;
  		    } else
  			free(keybindtab->removenode(keybindtab, s));
--- 924,933 ----
  			free(keybindtab->removenode(keybindtab, s));
  		} else {
  		    if (ky && ky->prefixct) {
! 			if (ky->func == z_sendstring) {
  			    zfree(ky->str, ky->len);
+ 			    ky->str = NULL;
+ 			}
  			ky->func = z_undefinedkey;
  		    } else
  			free(keybindtab->removenode(keybindtab, s));
***************
*** 995,1002 ****
  			*s = (char)0x80;
  		}
  	    if (cur) {
  		cur->func = func;
- 		zfree(cur->str, cur->len);
  	    } else
  		keybindtab->addnode(keybindtab, ztrdup(s), cur = makefunckey(func));
  	    if (firstzero)
--- 997,1007 ----
  			*s = (char)0x80;
  		}
  	    if (cur) {
+ 		if (cur->str) {
+ 		    zfree(cur->str, cur->len);
+ 		    cur->str = NULL;
+ 		}
  		cur->func = func;
  	    } else
  		keybindtab->addnode(keybindtab, ztrdup(s), cur = makefunckey(func));
  	    if (firstzero)

-- 
Peter Stephenson <pws@xxxxxx>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.



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