util-mem.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


#define SCMalloc(sz)   SCMallocFunc((sz))
#define SCRealloc(ptr, sz)   SCReallocFunc((ptr), (sz))
#define SCCalloc(nm, sz)   SCCallocFunc((nm), (sz))
#define SCStrdup(s)   SCStrdupFunc((s))
#define SCStrndup(s, n)   SCStrndupFunc((s), (n))
#define SCFree(p)   free((p))
#define SCMallocAligned(size, align)   SCMallocAlignedFunc((size), (align))
#define SCFreeAligned(p)   SCFreeAlignedFunc((p))


void * SCMallocFunc (const size_t sz)
void * SCReallocFunc (void *ptr, const size_t size)
void * SCCallocFunc (const size_t nm, const size_t sz)
char * SCStrdupFunc (const char *s)
char * SCStrndupFunc (const char *s, size_t n)
void * SCMallocAlignedFunc (const size_t size, const size_t align)
 wrapper for allocing aligned mem More...
void SCFreeAlignedFunc (void *ptr)
 Free aligned memory. More...

Detailed Description

Pablo Rincon Crespo
Bill Meeks

Utility Macros for memory management

Add wrappers for functions that allocate/free memory here. Currently we have malloc, calloc, realloc, strdup, strndup and free, but there are more.

Definition in file util-mem.h.

Macro Definition Documentation

◆ SCCalloc

#define SCCalloc (   nm,
)    SCCallocFunc((nm), (sz))

Definition at line 54 of file util-mem.h.

◆ SCFree

#define SCFree (   p)    free((p))

Definition at line 62 of file util-mem.h.

◆ SCFreeAligned

#define SCFreeAligned (   p)    SCFreeAlignedFunc((p))

Definition at line 78 of file util-mem.h.

◆ SCMalloc

#define SCMalloc (   sz)    SCMallocFunc((sz))

Definition at line 48 of file util-mem.h.

◆ SCMallocAligned

#define SCMallocAligned (   size,
)    SCMallocAlignedFunc((size), (align))

Definition at line 69 of file util-mem.h.

◆ SCRealloc

#define SCRealloc (   ptr,
)    SCReallocFunc((ptr), (sz))

Definition at line 51 of file util-mem.h.

◆ SCStrdup

#define SCStrdup (   s)    SCStrdupFunc((s))

Definition at line 57 of file util-mem.h.

◆ SCStrndup

#define SCStrndup (   s,
)    SCStrndupFunc((s), (n))

Definition at line 60 of file util-mem.h.

Function Documentation

◆ SCCallocFunc()

void* SCCallocFunc ( const size_t  nm,
const size_t  sz 

◆ SCFreeAlignedFunc()

void SCFreeAlignedFunc ( void *  ptr)

Free aligned memory.

Not needed for mem alloc'd by posix_memalign, but for possible future use of _mm_malloc needing _mm_free.

Definition at line 132 of file util-mem.c.

◆ SCMallocAlignedFunc()

void* SCMallocAlignedFunc ( const size_t  size,
const size_t  align 

wrapper for allocing aligned mem


Definition at line 103 of file util-mem.c.

References FatalError, SC_ATOMIC_GET, SC_ERR_FATAL, SC_ERR_MEM_ALLOC, SCLogError, SURICATA_INIT, and unlikely.

◆ SCMallocFunc()

void* SCMallocFunc ( const size_t  sz)

◆ SCReallocFunc()

void* SCReallocFunc ( void *  ptr,
const size_t  size 

◆ SCStrdupFunc()

char* SCStrdupFunc ( const char *  s)

◆ SCStrndupFunc()

char* SCStrndupFunc ( const char *  s,
size_t  n 

Definition at line 82 of file util-mem.c.

References FatalError, likely, SC_ATOMIC_GET, SC_ERR_FATAL, SC_ERR_MEM_ALLOC, SCLogError, strlcpy(), SURICATA_INIT, and unlikely.

Here is the call graph for this function: