Re: segmentation fault on calloc

From: Mathieu Fregeau (mathieu.fregeau_at_polymtl.ca)
Date: 11/02/03


Date: Sun, 2 Nov 2003 16:05:41 -0500

Hi Mans,

thank you. If I understand, the heap is used when you use malloc (or
new/delete in C++), is that right? an object, or the main function is not
created on the heap (?). For me, I don't see a difference (and I was not
making care of knowing that), since when I want to use memory, that is not
my problem, I just request it. I understand a little more now, but is it me
(the code) or the system that creates the heap? if that's me, I could
increase its size, or something like: when I request memory (calloc), the
minimum block allocated is xx, (?) can I change the xx for something larger?
(...how?), can I track the heap validity? in windows there is the
heapwalk( _HEAPINFO *info) function, but in unix, the _HEAPINFO is an
unkonwn type... even with the <malloc.h> and <errno.h> file included...?

My question now relates on the heap, how to check its validity, and how to
make it valid (or increases its size)..

thank you!

Mathieu

"Måns Rullgård" <mru@kth.se> a écrit dans le message de
news:yw1xwuaipl1j.fsf@kth.se...
>
> Top-posting corrected by Gnus.
>
> "Mathieu Fregeau" <mathieu.fregeau@polymtl.ca> writes:
>
> >> >> > code. Rewritting the code is NOT an option. (about 10 years of
> >> >> > developement at NASA).
> >> >>
> >> >> Unfortunately there are many cases where a decade of development has
> >> >> produced an astonishing amount terrible code. It might be working,
> >> >> but any attempt to tinker with it results in things breaking, as we
> >> >> have seen. If only people could structure their code a little bit.
> >> >
> >> > in fact it is structured, but it is not documented.
> >>
> >> OK for structured, but it uses global variables, which is bad. As for
> >> documentation, that's equally important to code quality when dealing
> >> with long-lived code. I can barely understand my own code that I
> >> wrote less than a year ago.
> >
> > in fact, there is documentation, but not intended to an eventual
> > developper to modify its source... only for a user! The long reply
> > list suggest me that nobody in the world have an idea of a
> > solution. am I right?
>
> Without seeing the source, it's impossible to come up with anything
> better than guesses, based on experience with similar problems. I've
> seen lots of crashes in malloc, calloc and free, and all of them were
> caused by either buffer overflows, or attempts to use freed memory.
>
> I noticed in another post of yours that you seemed a little uncertain
> about what the heap was. The heap is the memory area of a process not
> containing code, stack, or static data (global variables, whether
> declared "static" or not), i.e. the memory managed by malloc and
> friends. To be able to do its work, malloc must store some
> information, such as size of each allocated block and lists of free
> blocks. This information is stored on the head, some of it between
> blocks returned from malloc to the caller. If the program writes past
> the end of an allocated block, it is almost certain to overwrite some
> of malloc's internal data. This will go unnoticed until the next call
> to a memory management function (no other code is allowed to touch
> it). When malloc (or calloc, or free) is called the next time, it
> might me using corrupted data, and crash.
>
> --
> Måns Rullgård
> mru@kth.se



Relevant Pages

  • malloc realloc and pointers
    ... When we perform malloc(), the memory allocated dynamically comes from ... the heap area of the process in concern. ... perticular position in a buffer then on performing a ...
    (comp.lang.c)
  • Re: stack and heap
    ... books explain that local stack variables for each function are automatically allocated when function starts and deallocated when it exits. ... malloc() always takes memory in the heap. ...
    (comp.programming)
  • malloc and realloc
    ... When we perform malloc(), the memory allocated dynamically comes ... from the heap area of the process in concern. ... perticular position in a buffer then on performing a ...
    (comp.lang.c)
  • Re: Understanding Linux addr space, malloc, and heap
    ... > I don't understand what is happening with malloc and the heap in my ... > chunk of memory that holds dynamically-allocated memory. ... the "heap" is still brk in linux, however there is no 1:1 relation ... between heap and malloc. ...
    (Linux-Kernel)
  • Heaps and Foreigners
    ... Based on some discussions I've had about SBCL heap limitations on ... heap allocation. ... I mean use malloc to allocate as much ... memory in a single call as I can. ...
    (comp.lang.lisp)

Loading