Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problems with libc6 and malloc

2 views
Skip to first unread message

Andreas Lagemann

unread,
Dec 2, 2002, 6:32:36 PM12/2/02
to
Hi all!
I am trying to get a program running on my Debian woody box, wich did
run under Solaris. It's a large project using lex and yacc. It is
basically written in C though using some C++ features (like new) but no
OO-Structures. Therefore I have to use g++ to build it. I use version
2.95.4. The problem is that mallopt() from libc.so.6 (called by
malloc()) causes SEGFAULT. This is the function where the error appears!
The line which causes the SEGFAULT ist marked with "<====".


int AddVariableToNewType
(
char variablename_var[], // Variablenname
char datatype_var[] // Datentyp der Variable
)
{
if (newtypelistend_var->variabledef==NULL)
{
// Variablenliste ist leer
newtypelistend_var->variabledef=(variabledata_struct *)
malloc(sizeof(variabledata_struct)); <=========
if (newtypelistend_var->variabledef==NULL)
return 1;
newtypevariablelistend_var=newtypelistend_var->variabledef;
}
else
{
// es sind Eintraege vorhanden
newtypevariablelistend_var->next=(variabledata_struct*)
malloc(sizeof(variabledata_struct));
if (newtypevariablelistend_var->next==NULL)
return 1;
newtypevariablelistend_var=newtypevariablelistend_var->next;
}
strcpy(newtypevariablelistend_var->name,variablename_var);
strcpy(newtypevariablelistend_var->datatype,datatype_var);
newtypevariablelistend_var->next=NULL;
return 0;
}

I suspect the problem lies within libc6 but I did not find any bug
reports stating a problem with malloc() resp. mallopt(). So if anyone
had an idea what my problem was and how I could probably fix it, I would
be very grateful for any hint.
I'm not quite sure if this is the right newsgroup to post to, so if this
is the worng newsgroup I apologize and will be thankful if you could tell
me the correct one.

Thank you for reading!

With best regards,

Andreas

Jens.T...@physik.fu-berlin.de

unread,
Dec 2, 2002, 7:28:46 PM12/2/02
to

At least in my personal experience 100% of all cases of a segfault somewhere
in the innards of malloc() are due to some previous memory corruption. Since
malloc() and friends are probably one of the most-used parts of libc your
chances of having found a bug are extremely small, so before you even start
suspecting a bug in the libc you really should make 100% sure it's not due
to memory corruption somewhere else in your program (which one can't figure
out from the snippet you posted - the worst thing about memory corruption is
that it often becomes a problem only at places that seem to be completely
unrelated). And just because it seemed to work on a different machine does
not proof anything, you were just unlucky that it didn't also fail on the
other machine with a different malloc implementation - I had a program that
I had written on a DEC machine work for years and only segfault when trying
to run it on Linux because of a bug that just didn't show up on the DEC
machine.
Sorry for the bad news, Jens
--
_ _____ _____
| ||_ _||_ _| Jens.T...@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring

Paul Pluzhnikov

unread,
Dec 2, 2002, 11:54:29 PM12/2/02
to
Jens.T...@physik.fu-berlin.de writes:

> Andreas Lagemann <a...@informatik.tu-cottbus.de> wrote:
> > The problem is that mallopt() from libc.so.6 (called by
> > malloc()) causes SEGFAULT.

> At least in my personal experience 100% of all cases of a segfault somewhere


> in the innards of malloc() are due to some previous memory corruption. Since

May I add that valgrind will probably lead Andreas straight to
the problem. Other tools that may help are ccmalloc, dmalloc,
efence and mpatrol (all free), as well as Chaperon and Insure++ ($$)

Cheers,
--
In order to understand recursion you must first understand recursion.

Kasper Dupont

unread,
Dec 3, 2002, 6:40:54 AM12/3/02
to
Andreas Lagemann wrote:
>
> Hi all!
> I am trying to get a program running on my Debian woody box, wich did
> run under Solaris. It's a large project using lex and yacc. It is
> basically written in C though using some C++ features (like new) but no
> OO-Structures. Therefore I have to use g++ to build it. I use version
> 2.95.4. The problem is that mallopt() from libc.so.6 (called by
> malloc()) causes SEGFAULT.

http://www.daimi.au.dk/~kasperd/comp.os.linux.development.faq.html#SIGSEGV

--
Kasper Dupont -- der bruger for meget tid på usenet.
For sending spam use mailto:aaa...@daimi.au.dk
char *mybuf[1==1]; (2==3)[mybuf]="Hello World!";

0 new messages