File: Xmalloc.c

package info (click to toggle)
dmalloc 5.5.2-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,344 kB
  • ctags: 2,584
  • sloc: ansic: 13,021; makefile: 433; perl: 175; sh: 173; cpp: 36
file content (87 lines) | stat: -rw-r--r-- 1,527 bytes parent folder | download | duplicates (10)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Provide malloc library replacements for X Window System heap routines
 * 	XtCalloc
 * 	XtFree
 * 	XtMalloc
 * 	XtRealloc
 * so that we can get accurate caller data.
 *
 * David Hill
 */
#define DMALLOC_DISABLE

#include "conf.h"
#include "dmalloc.h"
#include "dmalloc_loc.h"
#include "dmalloc_lp.h"
#include "return.h"

#define DO_XT_ENTRY_POINTS 1
#if DO_XT_ENTRY_POINTS

static	void	_XtAllocError(const char *name)
{
  (void)write(STDERR, "Xt Error: ", 10);
  (void)write(STDERR, name, strlen(name));
  (void)write(STDERR, "\n", 1);
  exit(1);
}

char	*XtMalloc(unsigned size)
{
  char	*file, *ptr;
  
  GET_RET_ADDR(file);
  
  ptr = _malloc_leap(size > 0 ? size : 1, file, 0);
  if (ptr == NULL) {
    _XtAllocError("malloc");
  }
  
  return ptr;
}

void	XtFree(char *pnt)
{
  char	*file;
  
  GET_RET_ADDR(file);
  
  if (ptr != NULL) {
    _free_leap(pnt, file, 0);
  }
}

char	*XtCalloc(unsigned num_elements, unsigned size)
{
  char	*file;
  
  GET_RET_ADDR(file);
  
  ptr = _calloc_leap(num_elements, size ? size : 1, file, 0);
  if (ptr == NULL) {
    _XtAllocError("calloc");
  }
  
  return ptr;
}

/*
 * resizes OLD_PNT to SIZE bytes and return the new space after either copying
 * all of OLD_PNT to the new area or truncating.  returns 0L on error.
 */
char	*XtRealloc(char *ptr, unsigned size)
{
  char	*file;
  
  GET_RET_ADDR(file);
  
  ptr = _realloc_leap(ptr, size > 0 ? size : 1, file, 0);
  if (ptr == NULL) {
    _XtAllocError("realloc");
  }
  
  return ptr;
}

#endif /* DO_XT_ENTRY_POINTS */