mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-24 07:16:43 +00:00
Add mem.c and "mem.h" with emalloc() etc.
This commit is contained in:
parent
f995a2a42d
commit
5139d8d34d
@ -20,6 +20,7 @@ SRCS= $(NACL_SOURCES) $(SERVAL_SOURCES)
|
||||
MONITORCLIENTSRCS=conf.c \
|
||||
log.c \
|
||||
mkdir.c \
|
||||
mem.c \
|
||||
monitor-client.c \
|
||||
net.c \
|
||||
str.c \
|
||||
@ -29,6 +30,7 @@ MONITORCLIENTSRCS=conf.c \
|
||||
MDPCLIENTSRCS=conf.c \
|
||||
dataformats.c \
|
||||
mkdir.c \
|
||||
mem.c \
|
||||
log.c \
|
||||
mdp_client.c \
|
||||
net.c \
|
||||
|
@ -6,6 +6,7 @@ HDRS= fifo.h \
|
||||
rhizome.h \
|
||||
serval.h \
|
||||
str.h \
|
||||
mem.h \
|
||||
strbuf.h \
|
||||
strbuf_helpers.h \
|
||||
sha2.h \
|
||||
|
27
mem.c
27
mem.c
@ -52,3 +52,30 @@ char *_str_edup(struct __sourceloc __whence, const char *str)
|
||||
{
|
||||
return _strn_edup(__whence, str, strlen(str));
|
||||
}
|
||||
|
||||
#undef malloc
|
||||
#undef calloc
|
||||
#undef free
|
||||
#undef realloc
|
||||
|
||||
#define SDM_GUARD_AFTER 16384
|
||||
|
||||
void *_serval_debug_malloc(unsigned int bytes, struct __sourceloc __whence)
|
||||
{
|
||||
void *r=malloc(bytes+SDM_GUARD_AFTER);
|
||||
DEBUGF("malloc(%d) -> %p", bytes, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
void *_serval_debug_calloc(unsigned int bytes, unsigned int count, struct __sourceloc __whence)
|
||||
{
|
||||
void *r=calloc((bytes*count)+SDM_GUARD_AFTER,1);
|
||||
DEBUGF("calloc(%d,%d) -> %p", bytes, count, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
void _serval_debug_free(void *p, struct __sourceloc __whence)
|
||||
{
|
||||
free(p);
|
||||
DEBUGF("free(%p)", p);
|
||||
}
|
||||
|
11
mem.h
11
mem.h
@ -23,6 +23,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#include <sys/types.h>
|
||||
#include "log.h"
|
||||
|
||||
// #define MALLOC_PARANOIA
|
||||
|
||||
#ifdef MALLOC_PARANOIA
|
||||
#define malloc(X) _serval_debug_malloc(X,__WHENCE__)
|
||||
#define calloc(X,Y) _serval_debug_calloc(X,Y,__WHENCE__)
|
||||
#define free(X) _serval_debug_free(X,__WHENCE__)
|
||||
void *_serval_debug_malloc(unsigned int bytes, struct __sourceloc whence);
|
||||
void *_serval_debug_calloc(unsigned int bytes, unsigned int count, struct __sourceloc whence);
|
||||
void _serval_debug_free(void *p, struct __sourceloc whence);
|
||||
#endif
|
||||
|
||||
/* Equivalent to malloc(3), but logs an error before returning NULL.
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
|
@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "mem.h"
|
||||
#include "serval.h"
|
||||
#include "overlay_buffer.h"
|
||||
|
||||
@ -453,29 +454,3 @@ int ob_dump(struct overlay_buffer *b,char *desc)
|
||||
dump(NULL, b->bytes, b->position);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#undef malloc
|
||||
#undef calloc
|
||||
#undef free
|
||||
#undef realloc
|
||||
|
||||
#define SDM_GUARD_AFTER 16384
|
||||
void *_serval_debug_malloc(unsigned int bytes, struct __sourceloc __whence)
|
||||
{
|
||||
void *r=malloc(bytes+SDM_GUARD_AFTER);
|
||||
DEBUGF("malloc(%d) -> %p", bytes, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
void *_serval_debug_calloc(unsigned int bytes, unsigned int count, struct __sourceloc __whence)
|
||||
{
|
||||
void *r=calloc((bytes*count)+SDM_GUARD_AFTER,1);
|
||||
DEBUGF("calloc(%d,%d) -> %p", bytes, count, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
void _serval_debug_free(void *p, struct __sourceloc __whence)
|
||||
{
|
||||
free(p);
|
||||
DEBUGF("free(%p)", p);
|
||||
}
|
||||
|
14
serval.h
14
serval.h
@ -21,8 +21,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#ifndef __SERVALD_SERVALD_H
|
||||
#define __SERVALD_SERVALD_H
|
||||
|
||||
// #define MALLOC_PARANOIA
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
@ -112,6 +110,7 @@ struct in_addr {
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "constants.h"
|
||||
#include "mem.h"
|
||||
#include "xprintf.h"
|
||||
#include "log.h"
|
||||
#include "net.h"
|
||||
@ -623,17 +622,6 @@ int dump_payload(struct overlay_frame *p, char *message);
|
||||
|
||||
int urandombytes(unsigned char *x,unsigned long long xlen);
|
||||
|
||||
#ifdef MALLOC_PARANOIA
|
||||
#define malloc(X) _serval_debug_malloc(X,__WHENCE__)
|
||||
#define calloc(X,Y) _serval_debug_calloc(X,Y,__WHENCE__)
|
||||
#define free(X) _serval_debug_free(X,__WHENCE__)
|
||||
|
||||
void *_serval_debug_malloc(unsigned int bytes, struct __sourceloc whence);
|
||||
void *_serval_debug_calloc(unsigned int bytes, unsigned int count, struct __sourceloc whence);
|
||||
void _serval_debug_free(void *p, struct __sourceloc whence);
|
||||
#endif
|
||||
|
||||
|
||||
struct vomp_call_state;
|
||||
|
||||
void set_codec_flag(int codec, unsigned char *flags);
|
||||
|
@ -17,6 +17,7 @@ SERVAL_SOURCES = $(SERVAL_BASE)audiodevices.c \
|
||||
$(SERVAL_BASE)main.c \
|
||||
$(SERVAL_BASE)mdp_client.c \
|
||||
$(SERVAL_BASE)mkdir.c \
|
||||
$(SERVAL_BASE)mem.c \
|
||||
$(SERVAL_BASE)monitor.c \
|
||||
$(SERVAL_BASE)monitor-client.c \
|
||||
$(SERVAL_BASE)monitor-cli.c \
|
||||
|
Loading…
Reference in New Issue
Block a user