realloc bug?

Nikola Vladov <[email protected]>
Newsgroups gmane.linux.lib.dietlibc
Message-ID <[email protected]>
There is a bug in dietlibc realloc.  Build and start next file 
with strace and see that it uses 12 pages for 12 bytes at the end.
This is a good exercise for my students to fix the bug!

Another bug exists if one sets WANT_MALLOC_ZERO in dietfeatures.h
This is not very well tested (I'm not 100% sure).


-------------------
#include <stdlib.h>
#include <fime.h>

#define M 12
int main() {
  char *x[M];
  int k;
  for (k=0; k<M; k++)
    x[k] = malloc(6000);

  for (k=0; k<M; k++)
    if (x[k]) 
      realloc(x[k], 3000);

  for (k=0; k<M; k++)
    if (x[k]) 
      realloc(x[k], 1);

  /* sleep(300); */ 
  return 0;
}
-------------------

Nilkola

http://riemann.fmi.uni-sofia.bg/programs/diet/alloc.tar.gz
Seems that this realloc does not have above bug!  May be it have other, 
but I don't know where they are yet ;-)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.