struct tm* ltime;
ltime = localtime(&(mi->time));
strftime(fecha, 30, "%c", ltime);
- fprintf(fp, "0x%08X | %5u | %-25s | %-16s | %5u\n",
+ fprintf(fp, "| 0x%08X | %5u | %-30s | %-20s | %5u |\n",
(size_t)(mi->pointer),
mi->bytes,
fecha,
void memdebug_list_print(FILE* fp) {
MemInfo* mi;
- fprintf(fp, "%-10s | %-5s | %-25s | %-16s | %-5s\n",
+ fprintf(fp, "+------------+-------+--------------------------------+"
+ "----------------------+-------+\n");
+ fprintf(fp, "| %-10s | %-5s | %-30s | %-20s | %-5s |\n",
"Ptr",
"Bytes",
"Fecha",
"Archivo",
"Línea");
- fprintf(fp, "-----------+-------+---------------------------+"
- "------------------+------\n");
+ fprintf(fp, "+------------+-------+--------------------------------+"
+ "----------------------+-------+\n");
for (mi = DLList_begin(memdebug_list);
DLList_have_more(memdebug_list);
mi = DLList_next(memdebug_list)) {
memdebug_info_print(mi, fp);
}
+ fprintf(fp, "+------------+-------+--------------------------------+"
+ "----------------------+-------+\n");
}
void* memdebug_malloc(size_t bytes, const char* fname, size_t fline) {
/* Si hay una lista. */
if (memdebug_list) {
MemInfo* mi;
- /* Imprimo la lista. */
- memdebug_list_print(stderr);
+ /* Imprimo la lista si hay algun elemento. */
+ if (!DLList_empty(memdebug_list)) {
+ memdebug_list_print(stderr);
+ }
/* Libero la memoria de cada elemento y cada puntero almacenado. */
while (!DLList_empty(memdebug_list)) {
mi = DLList_pop(memdebug_list);
int main(void) {
/* Declaración de variables. */
void* ptr1 = malloc(1000);
- void* ptr2 = malloc(1000);
- void* ptr3 = malloc(1000);
+ void* ptr2 = malloc(0xFF);
+ void* ptr3 = malloc(010);
- memdebug_list_print(stderr);
-
- fprintf(stderr, "\n");
+ printf("\n");
+ printf("Memoria alocada hasta el momento:\n");
+ memdebug_list_print(stdout);
+ printf("\n");
free(ptr1);
free(ptr2);