Created attachment 144040 [details] Replace some ckalloc/ckfree calls in exp_clib.c with malloc/free. Hello, lang/expect 5.45_1 segfaults when C programs call exp_spawnv. This has been reported and fixed in Debian for a while: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=588817 Attached is the patch from Debian; it suffices to correct the problem. The Debian diff also includes a couple of sample programs that reproduce the segfault; leaving those out here, but they can be found, along with other patches, here: http://ftp.de.debian.org/debian/pool/main/e/expect/expect_5.45-2.diff.gz Thanks, Richard M Kreuter
Over to maintainers.
I don't think it's related to ckalloc / ckfree. The problem is the definition of Tcl_ErrnoMsg: #define Tcl_ErrnoMsg (tclStubsPtr->tcl_ErrnoMsg) I fear you don't have a properly setup interp. Please try this sample program: #include <sys/types.h> #include <unistd.h> #include <tcl.h> #include <expect.h> #include <expect_tcl.h> int main(void) { Tcl_Interp * interp = Tcl_CreateInterp(); Expect_Init(interp); char * date = "/bin/date"; char * args[] = {date, NULL}; int fd = exp_spawnv(date, args); char buf[64]; read(fd, buf, sizeof(buf)); puts(buf); close(fd); return (0); } Compile with something like this: cc -o test-spawn test-spawn.c -I/usr/local/include/tcl8.6 -I/usr/local/include -L/usr/local/lib -lexpect -ltcl86 It works as expected here. However, if you remove the assignment to interp and just leave the variable uninitialized or NULL-initialized, it will segfault exactly as you described.
The libexpect manual explicitly says that libexpect can be used directly from C or C++, without the use of Tcl, and there's no mention of needing to initialize a Tcl interpreter from C. (If that's now considered a deprecated/unsupported way to use libexpect, I guess it's just a documentation issue.)
libexpect(3) starts with #include expect_tcl.h Expect_Init(interp); cc files... -lexpect5.20 -ltcl7.5 -lm so you see that somehow tcl is included and linked against. I think they assume that interp is a correctly initialized interpreter. I agree that the documentation could be improved to assume less and explain more. Please report this upstream. Thank you,