Back to index

glibc  2.9
Functions | Variables
tst-mallocstate.c File Reference
#include <errno.h>
#include <stdio.h>
#include "malloc.h"

Go to the source code of this file.

Functions

static void merror (const char *msg)
int main (void)

Variables

static int errors = 0

Function Documentation

int main ( void  )

Definition at line 34 of file tst-mallocstate.c.

{
  void *p1, *p2;
  void *save_state;
  long i;

  errno = 0;

  p1 = malloc (10);
  if (p1 == NULL)
    merror ("malloc (10) failed.");

  p2 = malloc (20);
  if (p2 == NULL)
    merror ("malloc (20) failed.");

  free (malloc (10));

  for (i=0; i<100; ++i)
    {
      save_state = malloc_get_state ();
      if (save_state == NULL)
       {
         merror ("malloc_get_state () failed.");
         break;
       }
      /*free (malloc (10)); This could change the top chunk! */
      malloc_set_state (save_state);
      p1 = realloc (p1, i*4 + 4);
      if (p1 == NULL)
       merror ("realloc (i*4) failed.");
      free (save_state);
    }

  p1 = realloc (p1, 40);
  free (p2);
  p2 = malloc (10);
  if (p2 == NULL)
    merror ("malloc (10) failed.");
  free (p1);

  return errors != 0;
}

Here is the call graph for this function:

static void merror ( const char *  msg) [static]

Definition at line 27 of file tst-mallocstate.c.

{
  ++errors;
  printf ("Error: %s\n", msg);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int errors = 0 [static]

Definition at line 24 of file tst-mallocstate.c.