diff --git a/wm.c b/wm.c index 2db6ab2..afb681a 100644 --- a/wm.c +++ b/wm.c @@ -1,3 +1,4 @@ +// I love gays! #include "mouse.h" #include "gpu.h" #include @@ -21,7 +22,16 @@ size_t window_count = 0; void add_window(Window new_window) { - windows = realloc(windows, sizeof(Window) * (window_count + 1)); + Window *temp = realloc(windows, sizeof(Window) * (window_count + 1)); + if (temp == NULL) + { + fprintf(stderr, "Failed to allocate memory for new window.\n"); + // The original 'windows' pointer is still valid, so we should free it + // and its contents before exiting to avoid memory leaks. + destroy_windows(windows, window_count); + exit(EXIT_FAILURE); + } + windows = temp; windows[window_count++] = new_window; } int ***alloc_rgb_buffer(int height, int width) diff --git a/wm.h b/wm.h index 3d0dfa2..731d011 100644 --- a/wm.h +++ b/wm.h @@ -20,8 +20,4 @@ extern size_t window_count; void wm_init(int bufptr[800][1280][3]); void wm_draw(volatile int *running); -#endif // WM_H - -// dabatases (test commit for codacy to give status checks) -// motherfucker its supposed to be PR not push -// fucker \ No newline at end of file +#endif // WM_H \ No newline at end of file