Update version to 0.16
[ust.git] / libustinstr-malloc / mallocwrap.c
1 /*
2 * Copyright (C) 2009 Pierre-Marc Fournier
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #define _GNU_SOURCE
20 #include <dlfcn.h>
21 #include <sys/types.h>
22 #include <stdio.h>
23 #include <ust/marker.h>
24
25 void *malloc(size_t size)
26 {
27 static void *(*plibc_malloc)(size_t size) = NULL;
28 void *retval;
29
30 if (plibc_malloc == NULL) {
31 plibc_malloc = dlsym(RTLD_NEXT, "malloc");
32 if (plibc_malloc == NULL) {
33 fprintf(stderr, "mallocwrap: unable to find malloc\n");
34 return NULL;
35 }
36 }
37
38 retval = plibc_malloc(size);
39
40 ust_marker(malloc, "size %d ptr %p", (int)size, retval);
41
42 return retval;
43 }
44
45 void free(void *ptr)
46 {
47 static void *(*plibc_free)(void *ptr) = NULL;
48
49 if (plibc_free == NULL) {
50 plibc_free = dlsym(RTLD_NEXT, "free");
51 if (plibc_free == NULL) {
52 fprintf(stderr, "mallocwrap: unable to find free\n");
53 return;
54 }
55 }
56
57 ust_marker(free, "ptr %p", ptr);
58
59 plibc_free(ptr);
60 }
61
62 UST_MARKER_LIB
This page took 0.029261 seconds and 4 git commands to generate.