diff options
-rw-r--r-- | apps/wm.c | 2 | ||||
-rw-r--r-- | kernel/drivers/keyboard.c | 2 | ||||
-rw-r--r-- | kernel/features/proc.c | 2 | ||||
-rw-r--r-- | kernel/main.c | 1 | ||||
-rw-r--r-- | libc/inc/mem.h | 14 | ||||
-rw-r--r-- | libc/mem.c | 26 | ||||
-rw-r--r-- | libgui/gui.c | 2 | ||||
-rw-r--r-- | libgui/png.c | 8 |
8 files changed, 37 insertions, 20 deletions
@@ -332,6 +332,8 @@ int main(int argc, char **argv) default: break; } + + free(msg); }; return 0; diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c index ac97d36..e8690f1 100644 --- a/kernel/drivers/keyboard.c +++ b/kernel/drivers/keyboard.c @@ -28,8 +28,6 @@ void keyboard_handler() // TODO: "Merge" scancode to linux keycode? /* printf("%x %x = %x\n", scancode, state ? 0xe0 : 0, merged); */ - if (event) - free(event); event = malloc(sizeof(*event)); event->magic = KEYBOARD_MAGIC; event->press = (scancode & 0x80) == 0; diff --git a/kernel/features/proc.c b/kernel/features/proc.c index c0216bc..76da36d 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -90,7 +90,7 @@ void proc_send(struct proc *src, struct proc *dest, u32 type, void *data) struct proc_message *msg = malloc(sizeof(*msg)); msg->src = src; msg->dest = dest; - msg->msg = malloc(sizeof(struct message)); + msg->msg = malloc(sizeof(*msg->msg)); msg->msg->src = (int)src->pid; msg->msg->type = (int)type; msg->msg->data = data; diff --git a/kernel/main.c b/kernel/main.c index 665d474..563cae7 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -11,7 +11,6 @@ #include <mouse.h> #include <net.h> #include <pci.h> -#include <print.h> #include <serial.h> #include <syscall.h> #include <timer.h> diff --git a/libc/inc/mem.h b/libc/inc/mem.h index 9075736..4750efb 100644 --- a/libc/inc/mem.h +++ b/libc/inc/mem.h @@ -5,15 +5,19 @@ #include <def.h> +void *malloc_debug(u32 size, const char *file, int line, const char *func, const char *inp); +void free_debug(void *ptr, const char *file, int line, const char *func, const char *inp); +#define malloc(size) malloc_debug(size, __FILE__, __LINE__, __func__, #size) +#define free(ptr) free_debug(ptr, __FILE__, __LINE__, __func__, #ptr) + // Huh #ifdef kernel void heap_init(u32 start); -void *malloc(u32 size); -void free(void *ptr); +/* void *malloc(u32 size); */ +/* void free(void *ptr); */ #elif defined(userspace) -#include <print.h> -void *malloc(u32 size); -void free(void *ptr); +/* void *malloc(u32 size); */ +/* void free(void *ptr); */ #else #error "No lib target specified. Please use -Dkernel or -Duserspace" #endif @@ -235,7 +235,7 @@ void heap_init(u32 start) heap.end = start + HEAP_INIT_SIZE; } -void *malloc(u32 size) +void *_malloc(u32 size) { u32 index = bin_index(size); struct h_bin *temp = (struct h_bin *)&heap.bins[index]; @@ -279,8 +279,11 @@ void *malloc(u32 size) return &found->next; } -void free(void *p) +void _free(void *p) { + if (!p) + return; + struct h_bin *list; struct h_footer *new_foot, *old_foot; @@ -330,16 +333,27 @@ void free(void *p) #define kmalloc(n) (void *)sys1(SYS_MALLOC, n) #define kfree(ptr) (void)(sys1(SYS_FREE, (int)ptr)) -static u32 total = 0; -void *malloc(u32 size) +void *_malloc(u32 size) { - total += size; return kmalloc(size); } -void free(void *ptr) +void _free(void *ptr) { kfree(ptr); } #endif + +void *malloc_debug(u32 size, const char *file, int line, const char *func, const char *inp) +{ + printf("MALLOC:\t%s:%d: %s: %dB (%s)\n", file, line, func, size, inp); + return _malloc(size); +} + +void free_debug(void *ptr, const char *file, int line, const char *func, const char *inp) +{ + printf("FREE:\t%s:%d: %s: 0x%x (%s)\n", file, line, func, ptr, inp); + if (ptr) + _free(ptr); +} diff --git a/libgui/gui.c b/libgui/gui.c index afbc3ba..b675586 100644 --- a/libgui/gui.c +++ b/libgui/gui.c @@ -465,6 +465,7 @@ struct element *gui_add_text_input(struct element *container, int x, int y, u32 ((struct element_text_input *)text_input->data)->x = x; ((struct element_text_input *)text_input->data)->y = y; ((struct element_text_input *)text_input->data)->width = width; + ((struct element_text_input *)text_input->data)->text[0] = '\0'; ((struct element_text_input *)text_input->data)->color_fg = color_fg; ((struct element_text_input *)text_input->data)->color_bg = color_bg; ((struct element_text_input *)text_input->data)->font_type = font_type; @@ -590,6 +591,7 @@ void gui_event_loop(struct element *container) break; } } + free(msg); } diff --git a/libgui/png.c b/libgui/png.c index 2db6e4d..ad65eba 100644 --- a/libgui/png.c +++ b/libgui/png.c @@ -1125,9 +1125,8 @@ static struct png *png_new(void) void png_free(struct png *png) { // Deallocate image buffer - /* if (png->buffer != NULL) { */ - /* free(png->buffer); */ - /* } */ + if (png->buffer) + free(png->buffer); // Deallocate source buffer, if necessary png_free_source(png); @@ -1167,7 +1166,7 @@ struct bmp *png_load(const char *path) return NULL; void *buf = sread(path); - if (!png) { + if (!buf) { SET_ERROR(png, PNG_ENOTFOUND); png_free(png); return NULL; @@ -1190,7 +1189,6 @@ struct bmp *png_load(const char *path) bmp->pitch = png->width * (bmp->bpp >> 3); png_free(png); - free(buf); return bmp; } |