1 /***************************************************************************
4 * Sat Aug 30 17:00:48 2003
5 * Copyright 2003 Ricardo Markiewicz
7 ****************************************************************************/
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Library General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 /* este debe ser el ultimo include, para evitar errores de compilacion */
28 #include "malloc_debug.h"
30 /* Tengo que sacar los macros dentro de malloc_debug para evitar problemas */
34 typedef struct _t_malloc_ {
40 struct _t_malloc_ *next;
43 static t_MDAlloc *lstMalloc = NULL;
45 void *MD_malloc(int size, int line, char *file)
52 /* No registro nada porque no hay memoria! */
56 nodo = (t_MDAlloc *)malloc(sizeof(t_MDAlloc));
64 nodo->hora = time(NULL);
65 strncpy(nodo->file, file, 20);
67 /* Agrego el nodo al principio */
68 nodo->next = lstMalloc;
74 void MD_free(void *ptr)
76 /* Tengo que buscar el nodo alocado */
77 t_MDAlloc *node, *padre;
80 while (node != NULL) {
81 if (node->ptr == ptr) {
84 padre->next = node->next;
86 lstMalloc = node->next;
102 printf("+----------+--------+-%-20s-+---------+-------+----------+\n", "--------------------");
103 printf("|Direccion | TamaƱo | %-20s | Linea | Fecha | Hora |\n", "Archivo");
104 printf("+----------+--------+-%-20s-+---------+-------+----------+\n", "--------------------");
105 while (nodo != NULL) {
106 hora = localtime(&nodo->hora);
107 printf("|%p | % 6d | %-20s | % 7d | %02d/%02d | %02d:%02d:%02d |\n", \
108 nodo->ptr, nodo->size, nodo->file, nodo->line, hora->tm_mday, hora->tm_mon, \
109 hora->tm_hour, hora->tm_min, hora->tm_sec);
110 printf("+----------+--------+-%-20s-+---------+-------+----------+\n", "--------------------");