[PATCH] segmentation fault when do ls on local directory
Liu Yubao <[email protected]> Mon, 26 Mar 2007 10:00:09 +0800
| Newsgroups | gmane.network.lftp.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
Someone at a BBS found lftp on Debian Sid (lftp v3.5.9) gets a segmentation
fault when do ls on local directory:
gdb lftp
(gdb)set args file:///home/lyb
(gdb)run
>ls
.... directory list ....
segmentation fault
(gdb)bt
#0 0x080946a4 in StringSet::Empty (this=0x811fb98) at StringSet.cc:45
#1 0x080516cf in ~StringSet (this=0x811fb98) at StringSet.h:42
#2 0x080516ef in ~ArgV (this=0x811fb98) at ArgV.h:31
#3 0x08082ea0 in ~DirList (this=0x811a840) at FileAccess.cc:872
#4 0x080cdee6 in ~LocalDirList (this=0x811a840) at LocalAccess.cc:722
#5 0x0807cc37 in SMTask::Delete (task=0x811a840) at SMTask.cc:140
#6 0x080909fa in SMTask::_DeleteRef (task=0x811a840) at SMTask.h:94
#7 0x08090a0f in SMTask::DeleteRef<DirList> (task=@0x811f5b8) at SMTask.h:95
#8 0x0808d973 in ~FileCopyPeerDirList (this=0x811f500) at FileCopy.cc:1743
#9 0x0807cc37 in SMTask::Delete (task=0x811f540) at SMTask.cc:140
#10 0x080909fa in SMTask::_DeleteRef (task=0x811f540) at SMTask.h:94
#11 0x08090a66 in SMTask::DeleteRef<FileCopyPeer> (task=@0x811f6f0)
at SMTask.h:95
#12 0x08089308 in ~FileCopy (this=0x811f6c8) at FileCopy.cc:433
#13 0x0807cc37 in SMTask::Delete (task=0x811f6c8) at SMTask.cc:140
#14 0x0807028e in ~CopyJob (this=0x812b260) at CopyJob.cc:164
#15 0x0807cc37 in SMTask::Delete (task=0x812b260) at SMTask.cc:140
#16 0x08057606 in CmdExec::Do (this=0x810f718) at CmdExec.cc:566
#17 0x0807d3b4 in SMTask::Schedule () at SMTask.cc:241
#18 0x080520d1 in Job::WaitDone (this=0x810f718) at Job.cc:557
#19 0x0804dc0d in main (argc=2, argv=0xbfebf0f4) at lftp.cc:489
After digged the code, I guess I have got it. In FileAccess.h/cc,
DirList saves a pointer to its member "args" in its constructor
and disposes it in its destructor. This pointer comes from class
CmdExec in commands.cc:1352:CMD(ls),its lifecycle is shown below.
CmdExec::CmdExec(FileAccess *f,LocalDirectory *c) : SessionJob(f)
args = 0;
args_glob = 0;
void CmdExec::ExecParsed(ArgV *a,FDStream *o,bool b)
args = a;
int CmdExec::Do()
args=args_glob;
Job *CmdExec::builtin_glob()
assert(args_glob==0 && glob==0);
args_glob=new ArgV();
~CmdExec::CmdExec()
delete args;
delete args_glob;
I guess CmdExec is more important than DirList and has longer
lifecycle, it should hold the memory of "args" and is responsible
to dispose it, so here is the little patch (I don't subscribe this
mail list, please cc me if any question, 3x):
diff -aurN a\FileAccess.cc b\FileAccess.cc
--- a\FileAccess.cc Mon Mar 26 09:48:27 2007
+++ b\FileAccess.cc Mon Mar 26 09:44:38 2007
@@ -868,8 +868,6 @@
DirList::~DirList()
{
delete buf;
- if(args)
- delete args;
}
void FileAccess::CleanupAll()