summaryrefslogtreecommitdiffstats
path: root/lib/mm/dbg_malloc.h
blob: a4b016c17c6290306ea09c05b4af1b2cfde738f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * Copyright (C) 2001 Sistina Software (UK) Limited.
 *
 * This file is released under the GPL.
 */

#ifndef _LVM_DBG_MALLOC_H
#define _LVM_DBG_MALLOC_H

#include "lvm-types.h"
#include <stdlib.h>
#include <string.h>

#ifdef DEBUG_MEM
void *malloc_aux(size_t s, const char *file, int line);
void free_aux(void *p);
void *realloc_aux(void *p, unsigned int s, const char *file, int line);
int dump_memory(void);
void bounds_check(void);

#  define dbg_malloc(s) malloc_aux((s), __FILE__, __LINE__)
#  define dbg_free(p) free_aux(p)
#  define dbg_realloc(p, s) realloc_aux(p, s, __FILE__, __LINE__)
#else
#  define dbg_malloc(s) malloc(s)
#  define dbg_free(p) free(p)
#  define dbg_realloc(p, s) realloc(p, s)
#  define dump_memory()
#  define bounds_check()
#endif

static inline char *dbg_strdup(const char *str)
{
	char *ret = dbg_malloc(strlen(str) + 1);

	if (ret)
		strcpy(ret, str);

	return ret;
}

#endif