Skip to content
Snippets Groups Projects
Commit 2cbfa9be authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Memory leak hunting utilities.

parent 6752359a
No related branches found
No related tags found
No related merge requests found
Sat Sep 21 02:12:24 1991 Per Cederqvist (ceder at lysator) Sat Sep 21 02:12:24 1991 Per Cederqvist (ceder at lysator)
* ram-smalloc.c: Added support for memory leak finding.
* trace-mem.gdb, handle-malloc-dump.el: Useful for finding memory
leaks in the server. Compile ram-smalloc.c with DEBUG_MALLOC
defined.
* mux.c (mux_close): Fixed memory leak.
* ramkomd.c (main): Print how many blocks isc allocates.
* ramkomd.c: ip_client_port and ip_mux_port are local to ramkomd.c. * ramkomd.c: ip_client_port and ip_mux_port are local to ramkomd.c.
Tue Sep 17 23:04:39 1991 Per Cederqvist (ceder at lysator) Tue Sep 17 23:04:39 1991 Per Cederqvist (ceder at lysator)
......
/* /*
* $Id: ram-smalloc.c,v 0.6 1991/09/15 10:29:31 linus Exp $ * $Id: ram-smalloc.c,v 0.7 1991/09/21 12:19:24 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association. * Copyright (C) 1991 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -30,7 +30,14 @@ ...@@ -30,7 +30,14 @@
* TEST VERSION by ceder * TEST VERSION by ceder
*/ */
static char *rcsid = "$Id: ram-smalloc.c,v 0.6 1991/09/15 10:29:31 linus Exp $"; /*
* Define DEBUG_MALLOC to get traces from smalloc, srealloc and sfree.
* Run the resulting lyskomd under gdb. Source trace-mem.gdb. Run
* handle-malloc-dump.el on the resulting output.
*/
/* #define DEBUG_MALLOC */
static char *rcsid = "$Id: ram-smalloc.c,v 0.7 1991/09/21 12:19:24 ceder Exp $";
#include <stdio.h> #include <stdio.h>
...@@ -45,6 +52,16 @@ static char *rcsid = "$Id: ram-smalloc.c,v 0.6 1991/09/15 10:29:31 linus Exp $"; ...@@ -45,6 +52,16 @@ static char *rcsid = "$Id: ram-smalloc.c,v 0.6 1991/09/15 10:29:31 linus Exp $";
static int no_of_allocated_blocks = 0; static int no_of_allocated_blocks = 0;
#ifdef DEBUG_MALLOC
static void
trace_smalloc(size_t size,
void *result)
{
printf("smalloc:\nArg: 0x%lx\nRes: 0x%lx\n", (long)size, (long)result);
printf("==== end ====\n");
}
#endif
/* /*
* "safe" malloc. Handles the case when malloc returns NULL. * "safe" malloc. Handles the case when malloc returns NULL.
* smalloc cannot fail. * smalloc cannot fail.
...@@ -65,9 +82,21 @@ smalloc(size_t size) ...@@ -65,9 +82,21 @@ smalloc(size_t size)
((unsigned char *) p)[size] = 0x89; ((unsigned char *) p)[size] = 0x89;
((unsigned char *) p)[size+1] = 0xA7; ((unsigned char *) p)[size+1] = 0xA7;
#ifdef DEBUG_MALLOC
trace_smalloc(size, p);
#endif
return (void *) p; return (void *) p;
} }
#ifdef DEBUG_MALLOC
static void
trace_free(void *block)
{
printf("sfree:\nArg: 0x%lx\n", (long)block);
printf("==== end ====\n");
}
#endif
EXPORT void EXPORT void
sfree(void * ptr) /* it is legal to sfree a NULL pointer */ sfree(void * ptr) /* it is legal to sfree a NULL pointer */
...@@ -81,6 +110,9 @@ sfree(void * ptr) /* it is legal to sfree a NULL pointer */ ...@@ -81,6 +110,9 @@ sfree(void * ptr) /* it is legal to sfree a NULL pointer */
if ( ptr != NULL ) if ( ptr != NULL )
{ {
#ifdef DEBUG_MALLOC
trace_free(ptr);
#endif
ip = (unsigned int *) ptr; ip = (unsigned int *) ptr;
ip -= 2; ip -= 2;
switch (*ip) switch (*ip)
...@@ -103,6 +135,17 @@ sfree(void * ptr) /* it is legal to sfree a NULL pointer */ ...@@ -103,6 +135,17 @@ sfree(void * ptr) /* it is legal to sfree a NULL pointer */
} }
} }
#ifdef DEBUG_MALLOC
static void
trace_srealloc(size_t size,
void *arg,
void *result)
{
printf("srealloc:\nSize: 0x%lx\nArg: 0x%lx\nRes: 0x%lx\n",
(long)size, (long)arg, (long)result);
printf("==== end ====\n");
}
#endif
EXPORT void * EXPORT void *
srealloc(void * ptr, size_t size) /* Never fails. It is legal to */ srealloc(void * ptr, size_t size) /* Never fails. It is legal to */
{ /* realloc the NULL ptr. */ { /* realloc the NULL ptr. */
...@@ -145,6 +188,10 @@ srealloc(void * ptr, size_t size) /* Never fails. It is legal to */ ...@@ -145,6 +188,10 @@ srealloc(void * ptr, size_t size) /* Never fails. It is legal to */
((unsigned char *) new_ptr)[size] = 0x89; ((unsigned char *) new_ptr)[size] = 0x89;
((unsigned char *) new_ptr)[size+1] = 0xA7; ((unsigned char *) new_ptr)[size+1] = 0xA7;
#ifdef DEBUG_MALLOC
trace_srealloc(size, ptr, new_ptr);
#endif
return (void *) new_ptr; return (void *) new_ptr;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment