The big Memory-Eater strikes back

Knobi der Rechnerschrat XBR2D96D at DDATHD21.BITNET
Tue Sep 26 00:53:09 AEST 1989


Hallo,

  we have discorvered a memory-eating bug when using 'malloc(3x)'
instead of 'malloc(3m)'. The bug occurs under 3.1D when
using '-lmalloc' in the LIBR symbol of the following
sample code. the questions is:

a) is it a bug?
   -if 'yes', is it known?
b) do we use '-lmalloc' at an improper place?
c) what else?

It follows the sample code. 'make mem' gives the correct behaviour,
'make meml' gives you the memory eater. The code just runs a loop,
where some amount of memory is allocated and deallocated.

Regards
Martin Knoblauch

TH-Darmstadt
Physical Chemistry 1
Petersenstrasse 20
D-6100 Darmstadt, FRG

BITNET: <XBR2D96D at DDATHD21>
-------------------------------makefile---------------------------------
#
#  make - directives
#
CFLAGS = -g  -I/usr/include/bsd
#
# Library Selection
#
LIBRL = -lgl_s -lmalloc -lbsd -lfastm -lm -lc_s
LIBR = -lgl_s -lbsd -lfastm -lm -lc_s
#
#
#
mem:    mem.c
        cc mem.c $(CFLAGS) -o mem $(LIBR)
#
meml:   mem.c
        cc mem.c $(CFLAGS) -o meml $(LIBRL)
#
-------------------------------mem.c------------------------------------
/*
**      MOLCAD  Version 4.1
**
**      COPYRIGHT AND ALL OTHER RIGHTS RESERVED
**
**      Contact:
**
**       Prof. Dr. J. Brickmann
**       c/o TH - Darmstadt
**       Dept. for Physical Chemistry
**       Petersenstr. 20
**       D-6100 Darmstadt, FRG
**
**       BITNET  : <XBR2D96D at DDATHD21.BITNET>
**
**
**       file    :  mem.c
**       author  :  Martin Knoblauch + Michael Teschner
**       date    :
**       purpose :  memory allocation test
**       comment :
**
**
**
**
*/

#include <stdio.h>
#include <malloc.h>

int acount,dcount;

struct Dot { struct Dot *next;
             float arr[4];
            };

extern struct Dot *mk_Newdot();

main()
{
struct Dot *first,*dot;
int i,j,count;

first = NULL;

for(j=0;j<1000;j++){

    mk_Deldots(first);
    dot = first = NULL;

    count = 0;
    for(i=0;i<5000;i++){
      dot = mk_Newdot(dot);
       count++;
      if( first == NULL )  first = dot;
      }

 printf(" loop %d count %d \n",j,count);
 }

} /* end main */



struct Dot *mk_Newdot(prev)
struct Dot *prev;
{
struct Dot *help;

if ((help = (struct Dot *)malloc(sizeof(struct Dot))) == NULL)
        return(NULL);

if (prev != NULL) prev->next = help;
help->next = NULL;
return(help);
}


mk_Deldots(start)
struct Dot *start;
{
struct Dot *help;

while (start != NULL) {
  help = start->next;
  free(start);
  start = help;
  }
}



More information about the Comp.sys.sgi mailing list