#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):

 I've put the following two files into the `patches/` folder of the
 singular-3-1-5.malloc-linux spkg:

  * `sage_trac13731_gnc_mm_Mult_nn.patch`
    {{{
 #!diff
 # HG changeset patch
 # User Simon King <[email protected]>
 # Date 1353701669 -3600
 # Node ID 0f5e07666bc133a0d38cb846120c0103c4c2b0ae
 # Parent  3eb11c08dd9611b7fdba4622cc0d1660527f9e96
 #13731: Fix allocated size of F and G in gnc_mm_Mult_nn

 diff --git a/src/kernel/gring.cc b/src/kernel/gring.cc
 --- a/src/kernel/gring.cc
 +++ b/src/kernel/gring.cc
 @@ -469,8 +469,8 @@
    int rN=r->N;
    int
 ExpSize=(((rN+1)*sizeof(int)+sizeof(long)-1)/sizeof(long))*sizeof(long);

 -  int *F=(int *)omAlloc0((rN+1)*sizeof(int));
 -  int *G=(int *)omAlloc0((rN+1)*sizeof(int));
 +  int *F=(int *)omAlloc0(ExpSize);
 +  int *G=(int *)omAlloc0(ExpSize);

    memcpy(F, F0,(rN+1)*sizeof(int));
    // pExpVectorCopy(F,F0);
   }}}

  * patches/sage_trac13731_size_of_order.patch
    {{{
 #!diff
 # HG changeset patch
 # User Simon King <[email protected]>
 # Date 1353701944 -3600
 # Node ID 3ab3d75bf03794d94037c3e33711fdd773d858dc
 # Parent  0f5e07666bc133a0d38cb846120c0103c4c2b0ae
 #13731: Fix allocated size for order (in ring.cc)

 diff --git a/src/kernel/ring.cc b/src/kernel/ring.cc
 --- a/src/kernel/ring.cc
 +++ b/src/kernel/ring.cc
 @@ -154,7 +154,7 @@
  ring rDefault(int ch, int N, char **n)
  {
    /*order: lp,0*/
 -  int *order = (int *) omAlloc(2* sizeof(int));
 +  int *order = (int *) omAlloc(3* sizeof(int));
    int *block0 = (int *)omAlloc0(2 * sizeof(int));
    int *block1 = (int *)omAlloc0(2 * sizeof(int));
    /* ringorder dp for the first block: var 1..N */
    }}}

 However, after re-installing the package, the crash persists!
 {{{
 sage: A.<x,y> = FreeAlgebra(QQ, 2)
 sage: P.<x,y> = A.g_algebra({y*x:-x*y})
 sage: x*y
 *** glibc detected *** python: free(): invalid pointer: 0x0000000002bb11c0
 ***
 ======= Backtrace: =========
 /lib64/libc.so.6(+0x766d6)[0x7f8243e866d6]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libsingular.so(_Z14gnc_mm_Mult_nnPiS_P9sip_sring+0x294)[0x7f8229a81c54]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libsingular.so(_Z20gnc_p_Mult_mm_CommonP8spolyrecS0_iP9sip_sring+0x1ec)[0x7f8229a82acc]
 /home/simon/SAGE/debug/sage-5.5.rc0/local/lib/python2.7/site-
 packages/sage/libs/singular/polynomial.so(+0x4bd0)[0x7f8228e63bd0]
 /home/simon/SAGE/debug/sage-5.5.rc0/local/lib/python2.7/site-
 packages/sage/rings/polynomial/plural.so(+0x1fbd8)[0x7f82292a8bd8]
 /home/simon/SAGE/debug/sage-5.5.rc0/local/lib/python2.7/site-
 packages/sage/structure/element.so(+0x2a399)[0x7f823b0a7399]
 
/home/simon/SAGE/debug/sage-5.5.rc0/local/lib/libpython2.7.so.1.0(+0x48a4f)[0x7f8244a63a4f]
 }}}

 That's bad. Didn't you say the change fixes it for you?

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13731#comment:39>
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