#13731: Fix libsingular memory management
------------------------------------------------------------------+---------
       Reporter:  nbruin                                          |         
Owner:  rlm     
           Type:  defect                                          |        
Status:  new     
       Priority:  major                                           |     
Milestone:  sage-5.6
      Component:  memleak                                         |    
Resolution:          
       Keywords:                                                  |   Work 
issues:          
Report Upstream:  Reported upstream. Developers acknowledge bug.  |     
Reviewers:          
        Authors:                                                  |     Merged 
in:          
   Dependencies:                                                  |      
Stopgaps:          
------------------------------------------------------------------+---------

Comment (by SimonKing):

 With the help of the good people of [https://groups.google.com/forum/#!msg
 /libsingular-devel/AZI-6eZAgus/xx44G16DKRUJ libsingular-devel], I managed
 to create a
 
[http://sage.math.washington.edu/home/SimonKing/SAGE/spkgs/singular-3-1-5.p2.spkg
 new singular spkg].

 When you `export SINGULAR_XALLOC=yes` then the spkg creates a libsingular
 library and a Singular executable (yes, it starts and can compute
 things!!) with omalloc replaced by xalloc (a compatibility layer on top of
 malloc). Otherwise, the spkg just builds with omalloc.

 The good news:

 1. Singular works.
 {{{
 simon@linux-sqwp:~/SAGE/debug/sage-5.5.rc0> ./sage -singular
                      SINGULAR                                 /
 Development
  A Computer Algebra System for Polynomial Computations       /   version
 3-1-5
                                                            0<
  by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann     \   Jul 2012
 FB Mathematik der Universitaet, D-67653 Kaiserslautern        \
 > ring r;
 > x;
 x
 > x*y+z;
 xy+z
 > quit;
 Auf Wiedersehen.
 }}}
   There is no crash in the example above!
 2. Sage starts and quits just fine, even if libsingular is involved:
 {{{
 simon@linux-sqwp:~/SAGE/debug/sage-5.5.rc0> ./sage
 ----------------------------------------------------------------------
 | Sage Version 5.5.rc0, Release Date: 2012-11-17                     |
 | Type "notebook()" for the browser-based notebook interface.        |
 | Type "help()" for help.                                            |
 ----------------------------------------------------------------------
 **********************************************************************
 *                                                                    *
 * Warning: this is a prerelease version, and it may be unstable.     *
 *                                                                    *
 **********************************************************************
 sage: P.<x,y> = QQ[]
 sage: x*y
 x*y
 sage: quit
 Exiting Sage (CPU time 0m0.05s, Wall time 0m9.80s).
 }}}
 3. We can reproduce the error from the ticket description:
 {{{
 simon@linux-sqwp:~/SAGE/debug/sage-5.5.rc0> export MALLOC_CHECK_=3
 simon@linux-sqwp:~/SAGE/debug/sage-5.5.rc0> ./sage
 ----------------------------------------------------------------------
 | Sage Version 5.5.rc0, Release Date: 2012-11-17                     |
 | Type "notebook()" for the browser-based notebook interface.        |
 | Type "help()" for help.                                            |
 ----------------------------------------------------------------------
 **********************************************************************
 *                                                                    *
 * Warning: this is a prerelease version, and it may be unstable.     *
 *                                                                    *
 **********************************************************************
 sage: A.<x,y> = FreeAlgebra(QQ, 2)
 sage: P.<x,y> = A.g_algebra({y*x:-x*y})
 sage: x._mul_(y)
 *** glibc detected *** python: free(): invalid pointer: 0x0000000002cf4920
 ***
 ======= Backtrace: =========
 /lib64/libc.so.6(+0x766d6)[0x7f4331a486d6]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libsingular.so(_Z14gnc_mm_Mult_nnPiS_P9sip_sring+0x301)[0x7f431764de91]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libsingular.so(_Z20gnc_p_Mult_mm_CommonP8spolyrecS0_iP9sip_sring+0x21c)[0x7f431764ef5c]
 /home/simon/SAGE/debug/sage-5.5.rc0/local/lib/python2.7/site-
 packages/sage/libs/singular/polynomial.so(+0x4c60)[0x7f4316a2cc60]
 /home/simon/SAGE/debug/sage-5.5.rc0/local/lib/python2.7/site-
 packages/sage/rings/polynomial/plural.so(+0x1d278)[0x7f4316e70278]
 /home/simon/SAGE/debug/sage-5.5.rc0/local/lib/python2.7/site-
 packages/sage/rings/polynomial/plural.so(+0xbb63)[0x7f4316e5eb63]
 ...
 }}}
 4. Even better: We additionally get a crash when we do the example without
 `MALLOC_CHECK`, namely when quitting Sage:
 {{{
 simon@linux-sqwp:~/SAGE/debug/sage-5.5.rc0> export MALLOC_CHECK_=
 simon@linux-sqwp:~/SAGE/debug/sage-5.5.rc0> ./sage
 ----------------------------------------------------------------------
 | Sage Version 5.5.rc0, Release Date: 2012-11-17                     |
 | Type "notebook()" for the browser-based notebook interface.        |
 | Type "help()" for help.                                            |
 ----------------------------------------------------------------------
 **********************************************************************
 *                                                                    *
 * Warning: this is a prerelease version, and it may be unstable.     *
 *                                                                    *
 **********************************************************************
 sage: A.<x,y> = FreeAlgebra(QQ, 2)
 sage: P.<x,y> = A.g_algebra({y*x:-x*y})
 sage: x._mul_(y)
 x*y
 sage: quit
 Exiting Sage (CPU time 0m0.18s, Wall time 0m7.89s).
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libcsage.so(print_backtrace+0x31)[0x7f657e22bc77]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libcsage.so(sigdie+0x14)[0x7f657e22bca9]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libcsage.so(sage_signal_handler+0x216)[0x7f657e22b886]
 /lib64/libpthread.so.0(+0xfd00)[0x7f6583601d00]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libpython2.7.so.1.0(+0x129940)[0x7f6583938940]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libpython2.7.so.1.0(PyGC_Collect+0x24)[0x7f6583939694]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libpython2.7.so.1.0(Py_Finalize+0x116)[0x7f6583925316]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libpython2.7.so.1.0(Py_Exit+0x8)[0x7f6583924308]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libpython2.7.so.1.0(+0x115434)[0x7f6583924434]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libpython2.7.so.1.0(PyErr_PrintEx+0x205)[0x7f65839246d5]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libpython2.7.so.1.0(PyRun_SimpleFileExFlags+0x1fe)[0x7f6583924b4e]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libpython2.7.so.1.0(Py_Main+0xbd5)[0x7f6583938035]
 /lib64/libc.so.6(__libc_start_main+0xed)[0x7f6582c2523d]
 python[0x4006e1]

 ------------------------------------------------------------------------
 Unhandled SIGSEGV: A segmentation fault occurred in Sage.
 This probably occurred because a *compiled* component of Sage has a bug
 in it and is not properly wrapped with sig_on(), sig_off(). You might
 want to run Sage under gdb with 'sage -gdb' to debug this.
 Sage will now terminate.
 ------------------------------------------------------------------------
 /home/simon/SAGE/debug/sage-5.5.rc0/spkg/bin/sage: Zeile 310: 25245
 Speicherzugriffsfehler  sage-ipython "$@" -i
 }}}

 '''__Conclusion__'''

 I think this spkg is something we can work with to detect errors.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13731#comment:85>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to