jdf@ccvi.ccv.fr (Jean-Daniel Fekete) (07/05/89)
The following make bash barf in free. function zap() { if [ $# -gt 0 ] then for proc do for pid in $( ps -ax | grep $proc | grep -v grep | awk '{print $1}' ) do kill -KILL $pid &> /dev/null done done unset proc else echo "usage: zap <cmd> ..." fi } function hup() { if [ $# -gt 0 ] then for proc do for pid in $( ps -ax | grep $1 | grep -v grep | awk '{print $1}' ) do kill -HUP $pid &> /dev/null done done unset proc else echo "usage: hup <cmd> ..." fi } unset zap hup
chet@kiwi.CWRU.EDU (Chet Ramey) (07/06/89)
In article <8907041812.AA01639@ccvi.ccv.fr> jdf@ccvi.ccv.fr (Jean-Daniel Fekete) writes: >The following make bash barf in free. >function zap() >{ ... > kill -KILL $pid &> /dev/null ... >} >unset zap It's the redirections that are doing it. It's dispose_redirects() that is calling free() twice with the same redirection record (actually a portion of the same redirection record -- the filename). The problem is that when the command was copied (when the function was bound), the case of r_err_and_out was left out of the case statement in copy_cmd.c: copy_redirect(), so the filename part of the redirection struct never got copied, and was shared by both the command struct built by yyparse() and the command struct that is part of the function definition (whew :-). When the function definition was read and parsed, and the function installed, the command tree built in yyparse() was freed, and along with it the redirection info. Then, in unset_builtin, the copy of the command tree associated with the function struct was freed. The redirection info never was copied, so it was freed twice. The fix is amazingly simple. Once again, it is not the Officially Blessed fix; Brian might decide to do something different. However, it works. *** bash-1.01/copy_cmd.c Fri Jun 23 00:47:13 1989 --- src-1.01/copy_cmd.c Wed Jul 5 13:36:12 1989 *************** *** 96,99 case r_input_direction: case r_inputa_direction: new_redirect->redirectee.filename = copy_word (redirect->redirectee.filename); --- 96,100 ----- case r_input_direction: case r_inputa_direction: + case r_err_and_out: new_redirect->redirectee.filename = copy_word (redirect->redirectee.filename); Chet Ramey "We are preparing to think about contemplating Network Services Group, CWRU preliminary work on plans to develop a chet@cwjcc.INS.CWRU.Edu schedule for producing the 10th Edition of the Unix Programmers Manual." -- Andrew Hume
bfox@AUREL.CALTECH.EDU (Brian Fox) (07/06/89)
Date: Tue, 4 Jul 89 20:12:03 +0200 From: jdf@ccvi.ccv.fr (Jean-Daniel Fekete) The following make bash barf in free. function zap() { if [ $# -gt 0 ] then for proc do for pid in $( ps -ax | grep $proc | grep -v grep | awk '{print $1}' ) do kill -KILL $pid &> /dev/null done done unset proc else echo "usage: zap <cmd> ..." fi } function hup() { if [ $# -gt 0 ] then for proc do for pid in $( ps -ax | grep $1 | grep -v grep | awk '{print $1}' ) do kill -HUP $pid &> /dev/null done done unset proc else echo "usage: hup <cmd> ..." fi } unset zap hup Thanks. I have already fixed this bug. The function copy_redirection (), in the file copy_cmd.c did not copy the filename part of an `err_and_out' redirection. Just add it to the list in the case statement. Brian