Ejemplo n.º 1
0
/*=========================================================================*/
int xmalloc_report()
/*=========================================================================*/
{
    xallocation_t* x;

    if(G_xmalloc_fh)
    {
        fprintf(G_xmalloc_fh, 
                "\n*** Start of xmalloc_report ***\n");
    }
    x = (xallocation_t*)G_xmalloc_list.head;
    while(x)
    {
        _xmalloc_log(x);
        x = (xallocation_t*)(x->listitem.next);;
    }

    if(G_xmalloc_fh)
    {
	fprintf(G_xmalloc_fh, 
		"*** End of xmalloc_report ***\n\n");
    }

    return 0;

}
Ejemplo n.º 2
0
/*=========================================================================*/
void _xfree(const char* file,
            int line,
            void* buf)
/*=========================================================================*/
{
    xallocation_t* x;
     
    x =_xmalloc_find(buf);
    if(x == NULL)
    {
        if(G_xmalloc_fh)
        {
            fprintf(G_xmalloc_fh, 
                    "*** xfree called on non xmalloced memory ***\n");
        }

        return;
    }

    if(G_xmalloc_fh)
    {
        fprintf(G_xmalloc_fh,"Called xfree() %s:%i ",file,line);
        _xmalloc_log(x);
    }
    
    G_xmalloc_allocmem -= x->size;
    
    free(x->buf);
    
    free(SLPListUnlink(&G_xmalloc_list, (SLPListItem*)x));
}
Ejemplo n.º 3
0
/*=========================================================================*/
char* _xstrdup(const char* file,
               int line,
               const char* str)
/*=========================================================================*/
{
    xallocation_t* x;

    size_t strlength = strlen(str);

    if(G_xmalloc_freemem &&
       G_xmalloc_allocmem + strlength > G_xmalloc_freemem)
    {
        if(G_xmalloc_fh)
        {
            fprintf(G_xmalloc_fh,"\n*** Simulating out of memory error ***\n\n");
        }
        return NULL;
    }

    x = malloc(sizeof(xallocation_t));
    if(x == NULL)
    {
        if(G_xmalloc_fh)
        {
            fprintf(G_xmalloc_fh,"\n*** Real out of memory error ***\n\n");
        }
        return NULL;
    }

    x->buf = strdup(str);
    if(x->buf == NULL)
    {
        if(G_xmalloc_fh)
        {
            fprintf(G_xmalloc_fh,"\n*** Real out of memory error ***\n\n");
        }
        return NULL;
    }
    x->size = strlength;
    snprintf(x->where,SLPXMALLOC_MAX_WHERE_LEN,"%s:%i",file,line);
    G_xmalloc_allocmem += strlength;

    if(G_xmalloc_fh)
    {
        fprintf(G_xmalloc_fh,"Called xstrdup() %s:%i ",file,line);
        _xmalloc_log(x);
    }
    
    SLPListLinkTail(&G_xmalloc_list, (SLPListItem*)x);

    return (char*)x->buf;
}
Ejemplo n.º 4
0
/*=========================================================================*/
void* _xmalloc(const char* file,
               int line,
               size_t size)
/*=========================================================================*/
{
    xallocation_t* x;

    if(G_xmalloc_freemem &&
       G_xmalloc_allocmem + size > G_xmalloc_freemem)
    {
        if(G_xmalloc_fh)
        {
            fprintf(G_xmalloc_fh,"\n*** Simulating out of memory error ***\n\n");
        }
        return NULL;
    }

    x = malloc(sizeof(xallocation_t));
    if(x == NULL)
    {
        if(G_xmalloc_fh)
        {
            fprintf(G_xmalloc_fh,"\n*** Real out of memory error ***\n\n");
        }
        return NULL;
    }

    x->buf = malloc(size);
    if(x->buf == NULL)
    {
        if(G_xmalloc_fh)
        {
            fprintf(G_xmalloc_fh,"\n*** Real out of memory error ***\n\n");
        }
        return NULL;
    }
    SLPListLinkTail(&G_xmalloc_list, (SLPListItem*)x);

    x->size = size;
    snprintf(x->where,SLPXMALLOC_MAX_WHERE_LEN,"%s:%i",file,line);
    G_xmalloc_allocmem += size;

    if(G_xmalloc_fh)
    {
        fprintf(G_xmalloc_fh,"Called xmalloc() %s:%i ",file,line);
        _xmalloc_log(x);
    }
    
    
    return x->buf;
}
Ejemplo n.º 5
0
/** Report unfreed memory allocations to the debug memory log.
 *
 * @return 0
 */
int xmalloc_report(void)
{
   xallocation_t * x;

   if (G_xmalloc_fh)
      fprintf(G_xmalloc_fh, "\n*** Start of xmalloc_report ***\n");

   x = (xallocation_t *)G_xmalloc_list.head;
   while (x)
   {
      _xmalloc_log(x);
      x = (xallocation_t *)x->listitem.next;
   }

   if (G_xmalloc_fh)
      fprintf(G_xmalloc_fh, "*** End of xmalloc_report ***\n\n");

   return 0;
}
Ejemplo n.º 6
0
/** Free's a block of memory (DEBUG).
 *
 * @param[in] file - The file where @e xfree was called.
 * @param[in] line - The line number where @e xfree was called.
 * @param[in] ptr - The address of the block to be free'd.
 */
void _xfree(const char * file, int line, void * ptr)
{
   xallocation_t * x;

   x =_xmalloc_find(ptr);
   if (x == 0)
   {
      if (G_xmalloc_fh)
         fprintf(G_xmalloc_fh, "*** xfree called on "
               "non-xmalloc'd memory ***\n");
      return;
   }
   if (G_xmalloc_fh)
   {
      fprintf(G_xmalloc_fh, "Called xfree at %s:%i ", file, line);
      _xmalloc_log(x);
   }

   G_xmalloc_allocmem -= x->size;

   free(x->buf);
   free(SLPListUnlink(&G_xmalloc_list, (SLPListItem *)x));
}