From bug-request at octave dot org Tue Oct 18 15:37:45 2005 Subject: octave-2.9.3 atexit segfault From: "John W. Eaton" To: "Hall, Benjamin" Cc: "'bug at octave dot org'" Date: Tue, 18 Oct 2005 16:37:37 -0400 On 18-Oct-2005, Hall, Benjamin wrote: | The following causes a segfault for me in 2.9.3, but not earlier versions | (e.g., 2.1.64). | | octave ascript.m | --> panic: Segmentation fault -- stopping myself... | | interactively, it works fine | octave < ascript.m | --> I was here! | | where: | | file1: ascript.m | ====================== | atexit("afunc") | return | ====================== | | | file2: afunc.m | ====================== | function afunc() | disp("I was here!") | fflush(stdout); | ====================== | | | Changing "return" to "exit" fixes the problem. For my more involved scripts | I do not have a "return" at the end of the script (it just ends), but I | still get a seg fault. I couldn't reproduce that with a simpler test case | (without adding the "return"). | | Adding an explicit "exit" to the scripts fixes the problems, but makes it | difficult to run the same scripts truly interactively. Please try the following patch. Thanks, jwe src/ChangeLog 2005-10-18 John W. Eaton * octave.cc (octave_main): If not embedded, call clean_up_and_exit instead of return to exit function. Index: src/octave.cc =================================================================== RCS file: /cvs/octave/src/octave.cc,v retrieving revision 1.213 diff -u -r1.213 octave.cc --- src/octave.cc 26 Apr 2005 19:24:33 -0000 1.213 +++ src/octave.cc 18 Oct 2005 20:35:04 -0000 at @ -645,7 +645,7 @@ int parse_status = execute_eval_option_code (code_to_eval); if (! (persist || remaining_args > 0)) - return (parse_status || error_state ? 1 : 0); + clean_up_and_exit (parse_status || error_state ? 1 : 0); } if (remaining_args > 0) at @ -658,7 +658,7 @@ execute_command_line_file (argv[last_arg_idx]); if (! persist) - return (error_state ? 1 : 0); + clean_up_and_exit (error_state ? 1 : 0); } // Avoid counting commands executed from startup files. at @ -684,7 +684,13 @@ } if (embedded) - return 1; + { + // XXX FIXME XXX -- do we need to do any cleanup here before + // returning? If we don't, what will happen to Octave functions + // that have been registered to execute with atexit, for example? + + return 1; + } int retval = main_loop (); ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------