From: David Eduardo Gomez Noguera <davidgn@servidor.unam.mx>
To: Glynn Clements <glynn.clements@virgin.net>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: Memory bug somewhere
Date: 24 May 2003 14:47:05 -0500 [thread overview]
Message-ID: <1053805624.1248.35.camel@localhost.localdomain> (raw)
In-Reply-To: <16079.46351.86604.713178@cerise.nosuchdomain.co.uk>
On Sat, 2003-05-24 at 13:08, Glynn Clements wrote:
> David Eduardo Gomez Noguera wrote:
>
> > I have been having a program crash in this function.
> > It basically recives a pointer to a structure
> >
> > typedef struct hufftree {
> > HuffCode code;
> > struct hufftree *l;
> > struct hufftree *r;
> > }hufftree;
> >
> > a code, a size (of the code) and a data asigned to that huffman code.
> >
> > This function inserts the data at the end of the path marked by the code
> > and the size of the code.
> >
> > It segfaults after some asignments (some calls to ins_code), always at
> > the same point.
> >
> > Can anybody here see what is wrong with this?
>
> I can't see any errors here. However, if you corrupt the heap, you
> normally get a segfault during some subsequent call to malloc/free,
> not at the point that the corruption occurs.
>
> One option is to use mcheck(), e.g. by linking against libmcheck. This
> is mentioned in the libc Info file.
Thank you. I have just tried that, with the result that it went very
slow, and seemed to swap all memory (because after the program ends,
with the message "Killed", the output for free mem from `free` is all
the memory)
I called mcheck at the megening of main, with a NULL argument.
on other side, after reading a bit, I tried with
MALLOC_CHECK_ set to 1, but it dropped me only one message at the
beginig of all the output:
malloc: using debugging hooks
malloc: top chunk is corrupt
./sagem
I think that is before I use malloc even once.
have read a bit, but I think its not related to my problem.
With the printf statemens, I found the segfault was in the malloc call,
gdb's backtrace says that too:
Program received signal SIGSEGV, Segmentation fault.
0x400b682e in _int_malloc () from /lib/libc.so.6
(gdb) backtrace
#0 0x400b682e in _int_malloc () from /lib/libc.so.6
#1 0x400b5830 in malloc () from /lib/libc.so.6
#2 0x400b9aac in mallochook () from /lib/libc.so.6
#3 0x400b57cc in malloc () from /lib/libc.so.6
#4 0x08049c36 in ins_code (tree=0x804c3d0, code=78, size=7 '\a',
dato=161 '?')
at sagem.c:532
#5 0x08049ae1 in hs (hf=0xbfffdca0) at sagem.c:469
#6 0x08049618 in main (argc=2, argv=0xbfffde74) at sagem.c:258
#7 0x4005e5cd in __libc_start_main () from /lib/libc.so.6
Why I think it might be a problem with glibc is because it doesnt
segfaults on a mandrake 9.1, but it does crash on rh 8 and 9.
how could I be corrupting the heap if that is the problem?
next prev parent reply other threads:[~2003-05-24 19:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-05-24 17:48 Memory bug somewhere David Eduardo Gomez Noguera
2003-05-24 18:08 ` Glynn Clements
2003-05-24 19:47 ` David Eduardo Gomez Noguera [this message]
2003-05-24 23:52 ` Glynn Clements
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1053805624.1248.35.camel@localhost.localdomain \
--to=davidgn@servidor.unam.mx \
--cc=glynn.clements@virgin.net \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).