Discussion:
help with bus error/segfault
(too old to reply)
Xavier Noria
2007-05-15 18:14:08 UTC
Permalink
The last release of one of my modules works fine except in 5.6.2:

http://cpantesters.perl.org/show/Algorithm-
Combinatorics.html#Algorithm-Combinatorics-0.22

A tester reported the failure and I can reproduce it in my Mac with
5.6.2.

The test suite runs OK but for the last two tests of a single
subroutine (partitions_of_size_p), where Linux gives a segfault, and
in my Mac I get a bus error. This only happens in 5.6.2, it does not
happen in 5.8.x where the test suite passes.

I think it is unlikely that the function itself is buggy because the
tests verify result sets of several thousands of elements in 5.8.x,
so I wonder whether there's some XS gotcha behind this I am not aware
of. The code is pretty simple, I attach it below not to check what it
does, just to let you see whether you identify something that was
different in 5.6.2 and could be the culprit.

-- fxn

#define UPDATE(av, i, n) (SvIVX(AvARRAY(av)[i]) = n)
#define INCREMENT(av, i) (++SvIVX(AvARRAY(av)[i]))
#define GETIV(av, i) (SvIVX(AvARRAY(av)[i]))
#define GETAV(avptr) ((AV*) SvRV(avptr))

int __next_partition_of_size_p(SV* k_avptr, SV* M_avptr, int p)
{
AV* k = GETAV(k_avptr); /* follows notation in [3] */
AV* M = GETAV(M_avptr); /* follows notation in [3] */
int i, j;
IV mi, x;
I32 len_k, n_minus_p;

len_k = av_len(k);
for (i = len_k; i > 0; --i) {
if (GETIV(k, i) < p-1 && GETIV(k, i) <= GETIV(M, i-1)) {
INCREMENT(k, i);

if (GETIV(k, i) > GETIV(M, i))
UPDATE(M, i, GETIV(k, i));

n_minus_p = len_k + 1 - p;
mi = GETIV(M, i);
x = n_minus_p + mi;
for (j = i+1; j <= x; ++j) {
UPDATE(k, j, 0);
UPDATE(M, j, mi);
}
for (j = x+1; j <= len_k; ++j) {
UPDATE(k, j, j - n_minus_p);
UPDATE(M, j, j - n_minus_p);
}
return i;
}
}

return -1;
}
Marvin Humphrey
2007-05-16 05:37:35 UTC
Permalink
Post by Xavier Noria
A tester reported the failure and I can reproduce it in my Mac with
5.6.2.
Do you have access to a Linux box with Valgrind on it? I think your
best bet will be to use valgrind to track down exactly where the
error is happening.
Post by Xavier Noria
The code is pretty simple, I attach it below not to check what it
does, just to let you see whether you identify something that was
different in 5.6.2 and could be the culprit.
I don't think you've hit the lottery and found someone who's got the
changelog memorized. ;)

Cheers,

Marvin Humphrey
Rectangular Research
http://www.rectangular.com/
Xavier Noria
2007-05-16 12:58:28 UTC
Permalink
Post by Marvin Humphrey
Post by Xavier Noria
A tester reported the failure and I can reproduce it in my Mac
with 5.6.2.
Do you have access to a Linux box with Valgrind on it? I think
your best bet will be to use valgrind to track down exactly where
the error is happening.
Thank you!

Fortunately the tester that reported the problem (David Cantrell) is
so kind as to provide a SSH account on his Linux.

Indeed, if I run the test under Valgrind in 5.6.2 there's a

==15955== Invalid write of size 4
==15955== at 0x4A0829D: __next_partition_of_size_p (in /home/
perluser/FXN/Algorithm-Combinatorics-0.22/blib/arch/auto/Algorithm/
Combinatorics/Combinatorics.so)

But in 5.8.8 it completes the test, the only errors come at the
beginning and seem to be unrelated to the module (reported about
Perl_runops_standard). There were some under 5.6.2 like those as
well, but much less.

Diffing the Combinatorics.c generated by each perl the only
differences seem to be calls to PERL_UNUSED_VAR() in 5.6.2

#ifndef PERL_UNUSED_VAR
# define PERL_UNUSED_VAR(var) if (0) var = var
#endif

that are not generated by 5.8.8. Looks harmless, hmmmmmmm.

-- fxn
Marvin Humphrey
2007-05-16 16:11:00 UTC
Permalink
Post by Xavier Noria
Fortunately the tester that reported the problem (David Cantrell)
is so kind as to provide a SSH account on his Linux.
He's done that for me, too. Good bloke.
Post by Xavier Noria
Indeed, if I run the test under Valgrind in 5.6.2 there's a
==15955== Invalid write of size 4
==15955== at 0x4A0829D: __next_partition_of_size_p (in /home/
perluser/FXN/Algorithm-Combinatorics-0.22/blib/arch/auto/Algorithm/
Combinatorics/Combinatorics.so)
But in 5.8.8 it completes the test, the only errors come at the
beginning and seem to be unrelated to the module (reported about
Perl_runops_standard). There were some under 5.6.2 like those as
well, but much less.
Errors? I've seen leaks (including one in DynaLoader), but I don't
recall errors under 5.8.8.

I have a perl 5.8.8 compiled with -DDEBUGGING that I use for valgrind
testing, and I feed it this suppressions file:

http://xrl.us/wdve (Link to www.rectangular.com)

The full command is:

valgrind --leak-check=full --show-reachable=yes \
--suppressions=../devel/p588_valgrind.supp \
/usr/local/debugperl/bin/perl5.8.8 -Mblib \
t/test_file.t

More on these leaks in this thread.

http://www.nntp.perl.org/group/perl.xs/2007/01/msg2358.html
http://www.nntp.perl.org/group/perl.xs/2007/01/msg2357.html
Post by Xavier Noria
Diffing the Combinatorics.c generated by each perl the only
differences seem to be calls to PERL_UNUSED_VAR() in 5.6.2
#ifndef PERL_UNUSED_VAR
# define PERL_UNUSED_VAR(var) if (0) var = var
#endif
that are not generated by 5.8.8. Looks harmless, hmmmmmmm.
Yeah, that's just to avoid compiler warnings about unused variables.

You probably have the tools to track this down now. Throw in some
debug prints until you figure out exactly where in your test code the
error occurs. Keep reducing the test code... yada, yada, standard
bug isolation.

With Valgrind, debugging C becomes a lot more like debugging Perl. :)

Marvin Humphrey
Rectangular Research
http://www.rectangular.com/
Xavier Noria
2007-05-16 19:39:16 UTC
Permalink
Post by Marvin Humphrey
Post by Xavier Noria
Fortunately the tester that reported the problem (David Cantrell)
is so kind as to provide a SSH account on his Linux.
He's done that for me, too. Good bloke.
Post by Xavier Noria
Indeed, if I run the test under Valgrind in 5.6.2 there's a
==15955== Invalid write of size 4
==15955== at 0x4A0829D: __next_partition_of_size_p (in /home/
perluser/FXN/Algorithm-Combinatorics-0.22/blib/arch/auto/Algorithm/
Combinatorics/Combinatorics.so)
But in 5.8.8 it completes the test, the only errors come at the
beginning and seem to be unrelated to the module (reported about
Perl_runops_standard). There were some under 5.6.2 like those as
well, but much less.
Errors? I've seen leaks (including one in DynaLoader), but I don't
recall errors under 5.8.8.
This is the first time I use Valgrind. Using 5.8.8 the test suite
passes but there's a report that reads:

ERROR SUMMARY: 18 errors from 14 contexts (suppressed: 19 from 1)

and a lot of stuff I don't understand at the beginning. I copy the
output below. Do you smell in that report that albeit the tests pass
there may be some incorrect C code? For instance before the first ok
1 there's a suspicious

Invalid read of size 4

I'll try to figure out whether that happens before or while the first
test runs.
Post by Marvin Humphrey
I have a perl 5.8.8 compiled with -DDEBUGGING that I use for
http://xrl.us/wdve (Link to www.rectangular.com)
valgrind --leak-check=full --show-reachable=yes \
--suppressions=../devel/p588_valgrind.supp \
/usr/local/debugperl/bin/perl5.8.8 -Mblib \
t/test_file.t
More on these leaks in this thread.
http://www.nntp.perl.org/group/perl.xs/2007/01/msg2358.html
http://www.nntp.perl.org/group/perl.xs/2007/01/msg2357.html
Post by Xavier Noria
Diffing the Combinatorics.c generated by each perl the only
differences seem to be calls to PERL_UNUSED_VAR() in 5.6.2
#ifndef PERL_UNUSED_VAR
# define PERL_UNUSED_VAR(var) if (0) var = var
#endif
that are not generated by 5.8.8. Looks harmless, hmmmmmmm.
Yeah, that's just to avoid compiler warnings about unused variables.
You probably have the tools to track this down now. Throw in some
debug prints until you figure out exactly where in your test code
the error occurs. Keep reducing the test code... yada, yada,
standard bug isolation.
With Valgrind, debugging C becomes a lot more like debugging Perl. :)
Thank you! This stuff is new to me so I appreciate very much your
guidance.

-- fxn



***@pigsty:~/FXN/Algorithm-Combinatorics-0.22$ ~/FXN/local/bin/
valgrind --leak-check=yes perl5.8.8 -Mblib t/10_partitions_of_size_p.t
==29452== Memcheck, a memory error detector.
==29452== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et
al.
==29452== Using LibVEX rev 1732, a library for dynamic binary
translation.
==29452== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==29452== Using valgrind-3.2.3, a dynamic binary instrumentation
framework.
==29452== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et
al.
==29452== For more details, rerun with: -v
==29452==
==29452== Conditional jump or move depends on uninitialised value(s)
==29452== at 0x4010C4E: (within /lib/ld-2.3.6.so)
==29452== by 0x4006704: (within /lib/ld-2.3.6.so)
==29452== by 0x418C30F: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==29452==
==29452== Conditional jump or move depends on uninitialised value(s)
==29452== at 0x4010C5D: (within /lib/ld-2.3.6.so)
==29452== by 0x4006704: (within /lib/ld-2.3.6.so)
==29452== by 0x418C30F: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==29452==
==29452== Conditional jump or move depends on uninitialised value(s)
==29452== at 0x4010C6C: (within /lib/ld-2.3.6.so)
==29452== by 0x4006704: (within /lib/ld-2.3.6.so)
==29452== by 0x418C30F: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==29452==
==29452== Conditional jump or move depends on uninitialised value(s)
==29452== at 0x4010DDC: (within /lib/ld-2.3.6.so)
==29452== by 0x4006704: (within /lib/ld-2.3.6.so)
==29452== by 0x418C30F: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==29452==
==29452== Conditional jump or move depends on uninitialised value(s)
==29452== at 0x4010DDC: (within /lib/ld-2.3.6.so)
==29452== by 0x4004B78: (within /lib/ld-2.3.6.so)
==29452== by 0x4006792: (within /lib/ld-2.3.6.so)
==29452== by 0x418C30F: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452==
==29452== Invalid read of size 4
==29452== at 0x4010DD3: (within /lib/ld-2.3.6.so)
==29452== by 0x4004B78: (within /lib/ld-2.3.6.so)
==29452== by 0x4006792: (within /lib/ld-2.3.6.so)
==29452== by 0x418C30F: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452== Address 0x43A4268 is 32 bytes inside a block of size 34
alloc'd
==29452== at 0x401D4B0: malloc (vg_replace_malloc.c:149)
==29452== by 0x4005DA5: (within /lib/ld-2.3.6.so)
==29452== by 0x4006704: (within /lib/ld-2.3.6.so)
==29452== by 0x418C30F: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452==
==29452== Conditional jump or move depends on uninitialised value(s)
==29452== at 0x4008ED5: (within /lib/ld-2.3.6.so)
==29452== by 0x418C764: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==29452== by 0x80626BD: (within /usr/bin/perl5.8.8)
==29452==
==29452== Conditional jump or move depends on uninitialised value(s)
==29452== at 0x4008B2E: (within /lib/ld-2.3.6.so)
==29452== by 0x418C764: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==29452== by 0x80626BD: (within /usr/bin/perl5.8.8)
==29452==
==29452== Conditional jump or move depends on uninitialised value(s)
==29452== at 0x4010CC4: (within /lib/ld-2.3.6.so)
==29452== by 0x4006704: (within /lib/ld-2.3.6.so)
==29452== by 0x418C30F: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==29452==
==29452== Conditional jump or move depends on uninitialised value(s)
==29452== at 0x4010CCF: (within /lib/ld-2.3.6.so)
==29452== by 0x4006704: (within /lib/ld-2.3.6.so)
==29452== by 0x418C30F: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==29452==
==29452== Conditional jump or move depends on uninitialised value(s)
==29452== at 0x4010CDA: (within /lib/ld-2.3.6.so)
==29452== by 0x4006704: (within /lib/ld-2.3.6.so)
==29452== by 0x418C30F: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==29452==
==29452== Conditional jump or move depends on uninitialised value(s)
==29452== at 0x4010E0A: (within /lib/ld-2.3.6.so)
==29452== by 0x4006704: (within /lib/ld-2.3.6.so)
==29452== by 0x418C30F: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==29452==
==29452== Conditional jump or move depends on uninitialised value(s)
==29452== at 0x4010E0A: (within /lib/ld-2.3.6.so)
==29452== by 0x4004B78: (within /lib/ld-2.3.6.so)
==29452== by 0x4006792: (within /lib/ld-2.3.6.so)
==29452== by 0x418C30F: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452==
==29452== Invalid read of size 4
==29452== at 0x4010E00: (within /lib/ld-2.3.6.so)
==29452== by 0x4004B78: (within /lib/ld-2.3.6.so)
==29452== by 0x4006792: (within /lib/ld-2.3.6.so)
==29452== by 0x418C30F: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==29452== Address 0x463D970 is 40 bytes inside a block of size 41
alloc'd
==29452== at 0x401D4B0: malloc (vg_replace_malloc.c:149)
==29452== by 0x4005DA5: (within /lib/ld-2.3.6.so)
==29452== by 0x4006704: (within /lib/ld-2.3.6.so)
==29452== by 0x418C30F: (within /lib/libc-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==29452== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==29452== by 0x400B44E: (within /lib/ld-2.3.6.so)
==29452== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==29452== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==29452== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==29452== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
ok 1 -
ok 2 -
ok 3 -
ok 4 -
ok 5 -
ok 6 -
ok 7 -
ok 8 -
ok 9 -
ok 10 -
ok 11 -
ok 12 -
ok 13 -
ok 14 -
ok 15 -
ok 16 -
ok 17 -
ok 18 -
ok 19 -
ok 20 -
ok 21 -
ok 22 -
ok 23 -
ok 24 -
ok 25 -
ok 26 -
ok 27 -
ok 28 -
1..28
==29452==
==29452== ERROR SUMMARY: 18 errors from 14 contexts (suppressed: 19
from 1)
==29452== malloc/free: in use at exit: 1,714,030 bytes in 36,963 blocks.
==29452== malloc/free: 572,075 allocs, 535,112 frees, 10,832,681
bytes allocated.
==29452== For counts of detected errors, rerun with: -v
==29452== searching for pointers to 36,963 not-freed blocks.
==29452== checked 2,020,940 bytes.
==29452==
==29452==
==29452== 5 bytes in 1 blocks are definitely lost in loss record 1 of 21
==29452== at 0x401D4B0: malloc (vg_replace_malloc.c:149)
==29452== by 0x80AC69D: Perl_savesharedpv (in /usr/bin/perl5.8.8)
==29452== by 0x8064EF5: (within /usr/bin/perl5.8.8)
==29452== by 0x80671CB: perl_parse (in /usr/bin/perl5.8.8)
==29452== by 0x805FF71: main (in /usr/bin/perl5.8.8)
==29452==
==29452==
==29452== 68 bytes in 1 blocks are possibly lost in loss record 6 of 21
==29452== at 0x401C7EF: calloc (vg_replace_malloc.c:279)
==29452== by 0x400E188: (within /lib/ld-2.3.6.so)
==29452== by 0x400E214: (within /lib/ld-2.3.6.so)
==29452== by 0x400E257: _dl_allocate_tls (in /lib/ld-2.3.6.so)
==29452== by 0x4054FBD: __pthread_initialize_minimal (in /lib/
libpthread-0.10.so)
==29452== by 0x40511C4: (within /lib/libpthread-0.10.so)
==29452== by 0x4050BFF: (within /lib/libpthread-0.10.so)
==29452== by 0x400B7F4: (within /lib/ld-2.3.6.so)
==29452== by 0x400B94C: (within /lib/ld-2.3.6.so)
==29452== by 0x40007EE: (within /lib/ld-2.3.6.so)
==29452==
==29452==
==29452== 2,768 bytes in 1 blocks are possibly lost in loss record 13
of 21
==29452== at 0x401C6DB: memalign (vg_replace_malloc.c:332)
==29452== by 0x400E1E6: (within /lib/ld-2.3.6.so)
==29452== by 0x400E257: _dl_allocate_tls (in /lib/ld-2.3.6.so)
==29452== by 0x4054FBD: __pthread_initialize_minimal (in /lib/
libpthread-0.10.so)
==29452== by 0x40511C4: (within /lib/libpthread-0.10.so)
==29452== by 0x4050BFF: (within /lib/libpthread-0.10.so)
==29452== by 0x400B7F4: (within /lib/ld-2.3.6.so)
==29452== by 0x400B94C: (within /lib/ld-2.3.6.so)
==29452== by 0x40007EE: (within /lib/ld-2.3.6.so)
==29452==
==29452==
==29452== 12,410 (1,763 direct, 10,647 indirect) bytes in 15 blocks
are definitely lost in loss record 14 of 21
==29452== at 0x401D4B0: malloc (vg_replace_malloc.c:149)
==29452== by 0x80AC83E: Perl_safesysmalloc (in /usr/bin/perl5.8.8)
==29452== by 0x80EA9CA: Perl_new_stackinfo (in /usr/bin/perl5.8.8)
==29452== by 0x8061123: Perl_init_stacks (in /usr/bin/perl5.8.8)
==29452== by 0x80688CA: perl_construct (in /usr/bin/perl5.8.8)
==29452== by 0x805FF39: main (in /usr/bin/perl5.8.8)
==29452==
==29452==
==29452== 6,352 bytes in 2 blocks are definitely lost in loss record
16 of 21
==29452== at 0x401D5AB: realloc (vg_replace_malloc.c:306)
==29452== by 0x80AF267: Perl_safesysrealloc (in /usr/bin/perl5.8.8)
==29452== by 0x80EA86E: Perl_push_scope (in /usr/bin/perl5.8.8)
==29452== by 0x808A3F1: Perl_peep (in /usr/bin/perl5.8.8)
==29452== by 0x808A6B5: Perl_peep (in /usr/bin/perl5.8.8)
==29452== by 0x808A733: Perl_peep (in /usr/bin/perl5.8.8)
==29452== by 0x808A6B5: Perl_peep (in /usr/bin/perl5.8.8)
==29452== by 0x808A6B5: Perl_peep (in /usr/bin/perl5.8.8)
==29452== by 0x808A6B5: Perl_peep (in /usr/bin/perl5.8.8)
==29452== by 0x808A6B5: Perl_peep (in /usr/bin/perl5.8.8)
==29452== by 0x808A6B5: Perl_peep (in /usr/bin/perl5.8.8)
==29452== by 0x808A6B5: Perl_peep (in /usr/bin/perl5.8.8)
==29452==
==29452==
==29452== 180,628 bytes in 13 blocks are possibly lost in loss record
20 of 21
==29452== at 0x401D4B0: malloc (vg_replace_malloc.c:149)
==29452== by 0x80AC83E: Perl_safesysmalloc (in /usr/bin/perl5.8.8)
==29452== by 0x80B6646: Perl_reentrant_init (in /usr/bin/perl5.8.8)
==29452== by 0x8068AE5: perl_construct (in /usr/bin/perl5.8.8)
==29452== by 0x805FF39: main (in /usr/bin/perl5.8.8)
==29452==
==29452== LEAK SUMMARY:
==29452== definitely lost: 8,120 bytes in 18 blocks.
==29452== indirectly lost: 10,647 bytes in 20 blocks.
==29452== possibly lost: 183,464 bytes in 15 blocks.
==29452== still reachable: 1,511,799 bytes in 36,910 blocks.
==29452== suppressed: 0 bytes in 0 blocks.
==29452== Reachable blocks (those to which a pointer was found) are
not shown.
==29452== To see them, rerun with: --leak-check=full --show-
reachable=yes
Xavier Noria
2007-05-17 12:38:22 UTC
Permalink
Post by Xavier Noria
Post by Marvin Humphrey
Errors? I've seen leaks (including one in DynaLoader), but I
don't recall errors under 5.8.8.
This is the first time I use Valgrind. Using 5.8.8 the test suite
ERROR SUMMARY: 18 errors from 14 contexts (suppressed: 19 from 1)
and a lot of stuff I don't understand at the beginning. I copy the
output below. Do you smell in that report that albeit the tests
pass there may be some incorrect C code? For instance before the
first ok 1 there's a suspicious
Invalid read of size 4
I'll try to figure out whether that happens before or while the
first test runs.
Looks like those reported errors at the beginning are unrelated to my
module indeed, it is enough to load blib.pm to get them, I copy below
the output. In 5.6.2 the same command gives two errors "Conditional
jump...", and no "Invalid read...".

-- fxn


***@pigsty:~/FXN/Algorithm-Combinatorics-0.22$ ~/FXN/local/bin/
valgrind --leak-check=yes perl5.8.8 -Mblib -e1
==4099== Memcheck, a memory error detector.
==4099== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==4099== Using LibVEX rev 1732, a library for dynamic binary
translation.
==4099== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==4099== Using valgrind-3.2.3, a dynamic binary instrumentation
framework.
==4099== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==4099== For more details, rerun with: -v
==4099==
==4099== Conditional jump or move depends on uninitialised value(s)
==4099== at 0x4010C4E: (within /lib/ld-2.3.6.so)
==4099== by 0x4006704: (within /lib/ld-2.3.6.so)
==4099== by 0x418C30F: (within /lib/libc-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==4099== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==4099== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==4099== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==4099== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==4099== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==4099==
==4099== Conditional jump or move depends on uninitialised value(s)
==4099== at 0x4010C5D: (within /lib/ld-2.3.6.so)
==4099== by 0x4006704: (within /lib/ld-2.3.6.so)
==4099== by 0x418C30F: (within /lib/libc-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==4099== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==4099== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==4099== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==4099== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==4099== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==4099==
==4099== Conditional jump or move depends on uninitialised value(s)
==4099== at 0x4010C6C: (within /lib/ld-2.3.6.so)
==4099== by 0x4006704: (within /lib/ld-2.3.6.so)
==4099== by 0x418C30F: (within /lib/libc-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==4099== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==4099== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==4099== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==4099== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==4099== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==4099==
==4099== Conditional jump or move depends on uninitialised value(s)
==4099== at 0x4010DDC: (within /lib/ld-2.3.6.so)
==4099== by 0x4006704: (within /lib/ld-2.3.6.so)
==4099== by 0x418C30F: (within /lib/libc-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==4099== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==4099== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==4099== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==4099== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==4099== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==4099==
==4099== Conditional jump or move depends on uninitialised value(s)
==4099== at 0x4010DDC: (within /lib/ld-2.3.6.so)
==4099== by 0x4004B78: (within /lib/ld-2.3.6.so)
==4099== by 0x4006792: (within /lib/ld-2.3.6.so)
==4099== by 0x418C30F: (within /lib/libc-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==4099== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==4099== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==4099== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==4099== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==4099==
==4099== Invalid read of size 4
==4099== at 0x4010DD3: (within /lib/ld-2.3.6.so)
==4099== by 0x4004B78: (within /lib/ld-2.3.6.so)
==4099== by 0x4006792: (within /lib/ld-2.3.6.so)
==4099== by 0x418C30F: (within /lib/libc-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==4099== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==4099== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==4099== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==4099== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==4099== Address 0x43A42B8 is 32 bytes inside a block of size 34
alloc'd
==4099== at 0x401D4B0: malloc (vg_replace_malloc.c:149)
==4099== by 0x4005DA5: (within /lib/ld-2.3.6.so)
==4099== by 0x4006704: (within /lib/ld-2.3.6.so)
==4099== by 0x418C30F: (within /lib/libc-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==4099== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==4099== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==4099== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==4099== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==4099==
==4099== Conditional jump or move depends on uninitialised value(s)
==4099== at 0x4008ED5: (within /lib/ld-2.3.6.so)
==4099== by 0x418C764: (within /lib/libc-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==4099== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==4099== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==4099== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==4099== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==4099== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==4099== by 0x80626BD: (within /usr/bin/perl5.8.8)
==4099==
==4099== Conditional jump or move depends on uninitialised value(s)
==4099== at 0x4008B2E: (within /lib/ld-2.3.6.so)
==4099== by 0x418C764: (within /lib/libc-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x418BE9E: _dl_open (in /lib/libc-2.3.6.so)
==4099== by 0x4025D8D: (within /lib/libdl-2.3.6.so)
==4099== by 0x400B44E: (within /lib/ld-2.3.6.so)
==4099== by 0x40261BC: (within /lib/libdl-2.3.6.so)
==4099== by 0x4025D20: dlopen (in /lib/libdl-2.3.6.so)
==4099== by 0x8060A74: XS_DynaLoader_dl_load_file (in /usr/bin/
perl5.8.8)
==4099== by 0x80BDAD0: Perl_pp_entersub (in /usr/bin/perl5.8.8)
==4099== by 0x80BC3A8: Perl_runops_standard (in /usr/bin/perl5.8.8)
==4099== by 0x80626BD: (within /usr/bin/perl5.8.8)
==4099==
==4099== ERROR SUMMARY: 8 errors from 8 contexts (suppressed: 19 from 1)
==4099== malloc/free: in use at exit: 620,598 bytes in 9,985 blocks.
==4099== malloc/free: 17,614 allocs, 7,629 frees, 979,886 bytes
allocated.
==4099== For counts of detected errors, rerun with: -v
==4099== searching for pointers to 9,985 not-freed blocks.
==4099== checked 947,864 bytes.
==4099==
==4099==
==4099== 5 bytes in 1 blocks are definitely lost in loss record 1 of 21
==4099== at 0x401D4B0: malloc (vg_replace_malloc.c:149)
==4099== by 0x80AC69D: Perl_savesharedpv (in /usr/bin/perl5.8.8)
==4099== by 0x8064EF5: (within /usr/bin/perl5.8.8)
==4099== by 0x80671CB: perl_parse (in /usr/bin/perl5.8.8)
==4099== by 0x805FF71: main (in /usr/bin/perl5.8.8)
==4099==
==4099==
==4099== 68 bytes in 1 blocks are possibly lost in loss record 9 of 21
==4099== at 0x401C7EF: calloc (vg_replace_malloc.c:279)
==4099== by 0x400E188: (within /lib/ld-2.3.6.so)
==4099== by 0x400E214: (within /lib/ld-2.3.6.so)
==4099== by 0x400E257: _dl_allocate_tls (in /lib/ld-2.3.6.so)
==4099== by 0x4054FBD: __pthread_initialize_minimal (in /lib/
libpthread-0.10.so)
==4099== by 0x40511C4: (within /lib/libpthread-0.10.so)
==4099== by 0x4050BFF: (within /lib/libpthread-0.10.so)
==4099== by 0x400B7F4: (within /lib/ld-2.3.6.so)
==4099== by 0x400B94C: (within /lib/ld-2.3.6.so)
==4099== by 0x40007EE: (within /lib/ld-2.3.6.so)
==4099==
==4099==
==4099== 2,768 bytes in 1 blocks are possibly lost in loss record 14
of 21
==4099== at 0x401C6DB: memalign (vg_replace_malloc.c:332)
==4099== by 0x400E1E6: (within /lib/ld-2.3.6.so)
==4099== by 0x400E257: _dl_allocate_tls (in /lib/ld-2.3.6.so)
==4099== by 0x4054FBD: __pthread_initialize_minimal (in /lib/
libpthread-0.10.so)
==4099== by 0x40511C4: (within /lib/libpthread-0.10.so)
==4099== by 0x4050BFF: (within /lib/libpthread-0.10.so)
==4099== by 0x400B7F4: (within /lib/ld-2.3.6.so)
==4099== by 0x400B94C: (within /lib/ld-2.3.6.so)
==4099== by 0x40007EE: (within /lib/ld-2.3.6.so)
==4099==
==4099==
==4099== 10,433 (1,738 direct, 8,695 indirect) bytes in 15 blocks are
definitely lost in loss record 15 of 21
==4099== at 0x401D4B0: malloc (vg_replace_malloc.c:149)
==4099== by 0x80AC83E: Perl_safesysmalloc (in /usr/bin/perl5.8.8)
==4099== by 0x80EA9CA: Perl_new_stackinfo (in /usr/bin/perl5.8.8)
==4099== by 0x8061123: Perl_init_stacks (in /usr/bin/perl5.8.8)
==4099== by 0x80688CA: perl_construct (in /usr/bin/perl5.8.8)
==4099== by 0x805FF39: main (in /usr/bin/perl5.8.8)
==4099==
==4099==
==4099== 6,352 bytes in 2 blocks are definitely lost in loss record
17 of 21
==4099== at 0x401D5AB: realloc (vg_replace_malloc.c:306)
==4099== by 0x80AF267: Perl_safesysrealloc (in /usr/bin/perl5.8.8)
==4099== by 0x80EA86E: Perl_push_scope (in /usr/bin/perl5.8.8)
==4099== by 0x808A3F1: Perl_peep (in /usr/bin/perl5.8.8)
==4099== by 0x808A6B5: Perl_peep (in /usr/bin/perl5.8.8)
==4099== by 0x808A733: Perl_peep (in /usr/bin/perl5.8.8)
==4099== by 0x808A6B5: Perl_peep (in /usr/bin/perl5.8.8)
==4099== by 0x808A6B5: Perl_peep (in /usr/bin/perl5.8.8)
==4099== by 0x808A6B5: Perl_peep (in /usr/bin/perl5.8.8)
==4099== by 0x808A6B5: Perl_peep (in /usr/bin/perl5.8.8)
==4099== by 0x808A6B5: Perl_peep (in /usr/bin/perl5.8.8)
==4099== by 0x808A6B5: Perl_peep (in /usr/bin/perl5.8.8)
==4099==
==4099==
==4099== 180,628 bytes in 13 blocks are possibly lost in loss record
20 of 21
==4099== at 0x401D4B0: malloc (vg_replace_malloc.c:149)
==4099== by 0x80AC83E: Perl_safesysmalloc (in /usr/bin/perl5.8.8)
==4099== by 0x80C5AA0: (within /usr/bin/perl5.8.8)
==4099== by 0x80C9464: Perl_sv_upgrade (in /usr/bin/perl5.8.8)
==4099== by 0x8068BA3: perl_construct (in /usr/bin/perl5.8.8)
==4099== by 0x805FF39: main (in /usr/bin/perl5.8.8)
==4099==
==4099== LEAK SUMMARY:
==4099== definitely lost: 8,095 bytes in 18 blocks.
==4099== indirectly lost: 8,695 bytes in 18 blocks.
==4099== possibly lost: 183,464 bytes in 15 blocks.
==4099== still reachable: 420,344 bytes in 9,934 blocks.
==4099== suppressed: 0 bytes in 0 blocks.
==4099== Reachable blocks (those to which a pointer was found) are
not shown.
==4099== To see them, rerun with: --leak-check=full --show-reachable=yes
Marvin Humphrey
2007-05-17 15:10:33 UTC
Permalink
Post by Xavier Noria
Looks like those reported errors at the beginning are unrelated to
my module indeed, it is enough to load blib.pm to get them, I copy
below the output. In 5.6.2 the same command gives two errors
"Conditional jump...", and no "Invalid read...".
Since they seem to be harmless, you can add those to a suppressions
file.

http://valgrind.org/docs/manual/manual-core.html#manual-core.suppress
http://valgrind.org/docs/manual/mc-manual.html#mc-manual.suppfiles

That will clean up the output and make it easier to interpret.

BTW, perlhack has docs on using Perl with Valgrind.

http://perldoc.perl.org/perlhack.html

Marvin Humphrey
Rectangular Research
http://www.rectangular.com/
Xavier Noria
2007-05-18 00:58:41 UTC
Permalink
OK, I've got something. Very misterious!!!

Fortunately the segmentation fault happens in the first call to the
function and some printfs where enough to arrive to what seems the key.

The C subroutine receives an array in its second argument:

int __next_partition_of_size_p(SV* k_avptr, SV* M_avptr, int p) {
AV* k = GETAV(k_avptr);
AV* M = GETAV(M_avptr);
...
}

that is initialized in the Perl side:

my @M = (0) x $q;
push @M, $_ - $q + 1 for $q..(@$data-1);
...
__next_partition_of_size_p(\@k, \@M, $p)

The values of $q and @$data do not matter, they are correct. OK, \@M
is passed to the function as the second argument, and if I print its
contents in XS I get garbage from some index on. Just in case, that
call lives in a closure:

my $iter = Algorithm::Combinatorics::Iterator->new(sub {
__next_partition_of_size_p(\@k, \@M, $p) == -1 ? ...;
}, __slice_partition_of_size_p(\@k, $p, $data));


NOW THE MISTERY COMES, If I just print @M in Perl before that line,
the values in XS are right and execution completes without errors. I
mean, I just really added

print join(", ", @M), "\n";

before the call and all of a sudden the values of M in the XS side
are fine and thus the code completes OK.

I am puzzled here! Any ideas?

-- fxn
Xavier Noria
2007-05-19 10:01:55 UTC
Permalink
Post by Xavier Noria
OK, I've got something. Very misterious!!!
Fortunately the segmentation fault happens in the first call to the
function and some printfs where enough to arrive to what seems the key.
int __next_partition_of_size_p(SV* k_avptr, SV* M_avptr, int p) {
AV* k = GETAV(k_avptr);
AV* M = GETAV(M_avptr);
...
}
...
print its contents in XS I get garbage from some index on. Just in
my $iter = Algorithm::Combinatorics::Iterator->new(sub {
the values in XS are right and execution completes without errors.
I mean, I just really added
before the call and all of a sudden the values of M in the XS side
are fine and thus the code completes OK.
I am puzzled here! Any ideas?
That was the key in fact.

Problem was in 5.6.x there's no guarantee simple arithmetic with
integers gives an SV with a IV slot:

$ ~/local/perl-5.6.2/bin/perl -MDevel::Peek -e '$a = 1; $b = $a +
1; Dump $b'
SV = NV(0x180a810) at 0x1807730
REFCNT = 1
FLAGS = (NOK,pNOK)
NV = 2

Since the macro I used to pick integers was SvIVX my code was broken
in that version. Switching to SvIV is all I need to fix the module
for 5.6.x.

This changed in 5.8:

Perl now tries internally to use integer values in numeric
conversions
and basic arithmetics (+ − * /) if the arguments are integers, and
tries also to keep the results stored internally as integers. This
change leads to often slightly faster and always less lossy arith‐
metics. (Previously Perl always preferred floating point numbers
in its
math.)

But now that I reread that delta I see it just says "tries", so from
a formal point of view my use of SvIVX was incorrect even in 5.8.x,
albeit it worked in practice.

Marvin, thank you very much for your help.

-- fxn

Loading...