Back to index

avfs  1.0.1
Functions | Variables
alloc.c File Reference
#include "avfs.h"
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

static AV_LOCK_DECL (mallock)
void av_check_malloc ()
static void out_of_memory ()
void * av_malloc (avsize_t nbyte)
void * av_calloc (avsize_t nbyte)
void * av_realloc (void *ptr, avsize_t nbyte)
void av_free (void *ptr)

Variables

static int malloctr

Function Documentation

void* av_calloc ( avsize_t  nbyte)

Definition at line 57 of file alloc.c.

{
    void *p;

    AV_LOCK(mallock);
    malloctr ++;
    AV_UNLOCK(mallock);
    
    if(nbyte == 0)
        nbyte = 1;
    
    p = calloc(nbyte, 1);
    if(p == NULL)
       out_of_memory();

    return p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void av_check_malloc ( )

Definition at line 18 of file alloc.c.

{
    int ctr;

    AV_LOCK(mallock);
    ctr = malloctr;
    AV_UNLOCK(mallock);

    if(ctr != 0) 
        av_log(AVLOG_WARNING, "Unfreed memory remaining (%i)", ctr);
    else
        av_log(AVLOG_DEBUG, "No unfreed memory remaining");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void av_free ( void *  ptr)

Definition at line 96 of file alloc.c.

{
    AV_LOCK(mallock);
    if(ptr != NULL)
        malloctr --;
    AV_UNLOCK(mallock);

    if(ptr != NULL)
       free(ptr);
}
static AV_LOCK_DECL ( mallock  ) [static]
void* av_malloc ( avsize_t  nbyte)

Definition at line 39 of file alloc.c.

{
    void *p;

    AV_LOCK(mallock);
    malloctr ++;
    AV_UNLOCK(mallock);

    if(nbyte == 0)
        nbyte = 1;

    p = malloc(nbyte);
    if(p == NULL) 
        out_of_memory();
    
    return p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* av_realloc ( void *  ptr,
avsize_t  nbyte 
)

Definition at line 75 of file alloc.c.

{
    void *p;
    
    AV_LOCK(mallock);
    if(ptr == 0)
        malloctr ++;
    else if(nbyte == 0)
        malloctr --;
    AV_UNLOCK(mallock);

    if(ptr == NULL && nbyte == 0)
        nbyte = 1;

    p = realloc(ptr, nbyte);
    if(p == NULL)
        out_of_memory();
  
    return p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void out_of_memory ( ) [static]

Definition at line 32 of file alloc.c.

{
    av_log(AVLOG_ERROR, "Out of memory");
    fprintf(stderr, "Out of memory\n");
    exit(127);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int malloctr [static]

Definition at line 15 of file alloc.c.