From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by melb.werple.net.au (8.7.5/8.7.3) with ESMTP id HAA23972 for ; Fri, 10 May 1996 07:11:04 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id RAA11671; Thu, 9 May 1996 17:02:30 -0400 (EDT) Resent-Date: Thu, 9 May 1996 17:02:30 -0400 (EDT) From: Zoltan Hidvegi Message-Id: <199605092101.XAA00751@riesz.cs.elte.hu> Subject: Re: compctl bug with beta17 on Linux To: kaefer@aglaia.snafu.DE (Thorsten Meinecke) Date: Thu, 9 May 1996 23:01:53 +0200 (MET DST) Cc: zsh-workers@math.gatech.edu In-Reply-To: from Thorsten Meinecke at "May 9, 96 04:15:42 pm" Organization: Dept. of Comp. Sci., Eotvos University, Budapest, Hungary Phone: (36 1)2669833 ext: 2667, home phone: (36 1) 2752368 X-Mailer: ELM [version 2.4ME+ PL15 (25)] MIME-Version: 1.0 Content-Type: application/pgp; format=text; x-action=sign Content-Transfer-Encoding: 7bit Resent-Message-ID: <"MRuHm1.0.Hs2.brban"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/1039 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu -----BEGIN PGP SIGNED MESSAGE----- Thorsten wrote: > Methinks cmdstr is freed by freeheap() in docomplete(), in this case. You are right. I did not look at the code carefully enough. > I beg to differ :-) Stylistical issues aside (freeing a char* before > ever using it, even if it's guaranteed to be initialised with NULL), It is done in many other places in zsh. I think it is OK. > Zoltan's patch will fall over, when for whatever reason there's more than > one command position considered in the do/while-loop in get_comp_string(). > Invariably this will lead to memory leaks. For example, when quotes and > newlines are involved: > > % somecommand " > > anystring " > ^ here's the cursor, and completion is requested > > cmdstr will point to "anystring", but the memory occupied previously by > "somecommand" won't never be released. That "anystring" is the result > might be seen as a bug in its own right, but who says that something like > this will never happen? You are right here. It is not a bug. The same happens if you complete somecommand ; anystring. Here is a patch again. This overrides my previous patch. Zoltan *** Src/zle_tricky.c 1996/05/07 20:49:17 2.26 --- Src/zle_tricky.c 1996/05/09 20:49:09 *************** *** 871,876 **** --- 871,877 ---- parbegin = parend = -1; lincmd = incmdpos; linredir = inredir; + zsfree(cmdstr); cmdstr = NULL; zleparse = 1; clwpos = -1; *************** *** 903,912 **** else /* Otherwise reset the variables we are collecting data in. */ i = tt0 = cp = rd = 0; ! if (lincmd && tok == STRING) /* The lexer says, this token is in command position, so store the token string (to find the right compctl). */ ! cmdstr = dupstring(tokstr), i = 0; if (!zleparse && !tt0) { /* This is done when the lexer reached the word the cursor is on. */ --- 904,916 ---- else /* Otherwise reset the variables we are collecting data in. */ i = tt0 = cp = rd = 0; ! if (lincmd && tok == STRING) { /* The lexer says, this token is in command position, so store the token string (to find the right compctl). */ ! zsfree(cmdstr); ! cmdstr = ztrdup(tokstr); ! i = 0; ! } if (!zleparse && !tt0) { /* This is done when the lexer reached the word the cursor is on. */ -----BEGIN PGP SIGNATURE----- Version: 2.6.2i iQCVAwUBMZJdPwupSCiLN749AQG0NAP+Plywa8lZCf8IK2zGRktJ+8x+7fWIx9NO WcFUtNsL2Nt42QBOOx2KE1vUzOpTw14Ce4T1ec4Exg/2gpuRI/+HXhwJI4W7p0vm 6eLJqMq7TvVW35V6lXZgWqUPcEIJUxu6DZx/C0R/bqAbs+tZeCvg/7faUif4fZi0 8uSPwngyXqQ= =0LtK -----END PGP SIGNATURE-----