Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gmpz leak in gmp.pxi #566

Closed
sagetrac-mabshoff mannequin opened this issue Sep 2, 2007 · 5 comments
Closed

gmpz leak in gmp.pxi #566

sagetrac-mabshoff mannequin opened this issue Sep 2, 2007 · 5 comments
Assignees
Milestone

Comments

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Sep 2, 2007

Hello,

every piece of code that includes gmp.pxi leaks at least one gmpz:

  /* "/tmp/Work2/sage-2.8.3.rc3/devel/sage-main/sage/rings/../ext/gmp.pxi":66
 * cdef mpq_t tmp
 * mpz_init(u);  mpz_init(v); mpz_init(q)
 * mpz_init(u0); mpz_init(u1); mpz_init(u2)             # <<<<<<<<<<<<<<
 * mpz_init(v0); mpz_init(v1); mpz_init(v2)
 * mpz_init(t0); mpz_init(t1); mpz_init(t2)
 */
  mpz_init(__pyx_v_8rational_u0);

Valgrind says:

==25825== 8 bytes in 1 blocks are still reachable in loss record 349 of 2,539
==25825==    at 0x4A05809: malloc (vg_replace_malloc.c:149)
==25825==    by 0x94A2697: __gmpz_init (in /tmp/Work2/sage-2.8.3.rc3/local/lib/libgmp.so.3.4.1)
==25825==    by 0x169D8914: initrational (rational.c:10891)
==25825==    by 0x49F762: _PyImport_LoadDynamicModule (importdl.c:53)
==25825==    by 0x49D63E: import_submodule (import.c:2394)
==25825==    by 0x49DB11: load_next (import.c:2214)
==25825==    by 0x49DD6E: import_module_level (import.c:2002)
==25825==    by 0x49E1A4: PyImport_ImportModuleLevel (import.c:2066)
==25825==    by 0x47D5D8: builtin___import__ (bltinmodule.c:47)
==25825==    by 0x4156A2: PyObject_Call (abstract.c:1860)
==25825==    by 0x47DB71: PyEval_CallObjectWithKeywords (ceval.c:3433)
==25825==    by 0x480BD3: PyEval_EvalFrameEx (ceval.c:2063)

This leak is usually 8 bytes only, so this counts as noise.

Cheers,

Michael

Component: memleak

Issue created by migration from https://trac.sagemath.org/ticket/566

@sagetrac-mabshoff sagetrac-mabshoff mannequin added this to the sage-2.8.4 milestone Sep 2, 2007
@sagetrac-mabshoff sagetrac-mabshoff mannequin added t: bug labels Sep 2, 2007
@sagetrac-mabshoff sagetrac-mabshoff mannequin self-assigned this Sep 2, 2007
@sagetrac-mabshoff
Copy link
Mannequin Author

sagetrac-mabshoff mannequin commented Sep 2, 2007

comment:2
[00:58] <sage> No -- there is a separate copy of the entire gmp.pxi in each file that includes it.
[00:58] <sage> It's not shared at all.
[00:59] <sage> Some of gmp.pxi should be moved to c_lib, i.e., to libsage.so
[00:59] <mabshoff> So the *.pxi are really includes.
[00:59] <sage> Then it would all be shared.

After the move we need to define a cleanup routine and call that routine from sage/all.py

Cheers,

Michael

@malb
Copy link
Member

malb commented Sep 6, 2007

Attachment: gmp_leak.patch.gz

@williamstein
Copy link
Contributor

comment:4

This actually crashes numerous doctests, e.g., modular/modsym/space.py.

I've posted (to the official repo) this patch, but with a following patch
that modifies a few lines of gmp.pxi to disable the effects of this patch.
So you should pull the lates (hg_sage.pull()), then edit gmp.pxi to re-enable
this patch, then build, then do this many times:

sage@modular:~/d/sage/sage/modular/modsym$ sage -t space.py

You'll see numerous memory allocation errors.

@williamstein williamstein reopened this Sep 7, 2007
@williamstein williamstein modified the milestones: sage-2.8.4, sage-2.9 Sep 7, 2007
@malb
Copy link
Member

malb commented Sep 7, 2007

comment:5

Fixed in attached segfault-fix.patch. The problem was that vector_times_matrix in Matrix_rational_dense used the global mpz_t y locally as mpq_t and cleared it.

@malb
Copy link
Member

malb commented Sep 7, 2007

Attachment: segfault-fix.patch.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants