Use glib's malloc functions when compiled with LIBGTOP_ENABLE_DEBUG.

1999-10-24  Martin Baulig  <martin@home-of-linux.org>

	* xmalloc.c: Use glib's malloc functions when compiled
	with LIBGTOP_ENABLE_DEBUG.

	* xmalloc_suid.c: New file.
This commit is contained in:
Martin Baulig
1999-10-24 16:19:48 +00:00
committed by Martin Baulig
parent 17627bab9f
commit eeaa766456
4 changed files with 104 additions and 1 deletions

View File

@@ -23,22 +23,33 @@
#include <glibtop/xmalloc.h>
#if LIBGTOP_ENABLE_DEBUG
#include <glib.h>
#endif
/* Wrappers to malloc, calloc, realloc ... */
void *
glibtop_malloc_r (glibtop *server, size_t size)
{
#if LIBGTOP_ENABLE_DEBUG
return g_malloc0 (size);
#else
void *buf = malloc (size);
if (!buf)
glibtop_error_io_r (server, "malloc %d bytes", size);
return buf;
#endif
}
void *
glibtop_calloc_r (glibtop *server, size_t nmemb, size_t size)
{
#if LIBGTOP_ENABLE_DEBUG
return g_malloc0 (size * nmemb);
#else
void *buf = calloc (nmemb, size);
if (!buf)
@@ -46,27 +57,40 @@ glibtop_calloc_r (glibtop *server, size_t nmemb, size_t size)
nmemb, size);
return buf;
#endif
}
void *
glibtop_realloc_r (glibtop *server, void *ptr, size_t size)
{
#if LIBGTOP_ENABLE_DEBUG
return g_realloc (ptr, size);
#else
void *buf = realloc (ptr, size);
if (!buf)
glibtop_error_io_r (server, "realloc %d bytes", size);
return buf;
#endif
}
char *
glibtop_strdup_r (glibtop *server, const char *string)
{
#if LIBGTOP_DEBUG
return g_strdup (string);
#else
return strcpy (glibtop_malloc_r (server, strlen (string) + 1), string);
#endif
}
void
glibtop_free_r (glibtop *server, const void *ptr)
{
#if LIBGTOP_DEBUG
g_free (ptr);
#else
if (ptr) free ((void *) ptr);
#endif
}