Skip to content

Commit

Permalink
Memory fixes (#1705)
Browse files Browse the repository at this point in the history
* fix: free-before-init in renwin_init_surface when using sdl renderer

`ren->rensurface.surface` presupposes zero-initialized rensurface.
Rensurface was not actually zero-initialized.
It is now.

* fix: heap buffer overflow in process_env_free

`process_env_free` presupposed that it was null-terminated.
Pass length to free instead.

* use calloc instead of memset for zero-init

Co-authored-by: Guldoman <giulio.lettieri@gmail.com>

---------

Co-authored-by: Guldoman <giulio.lettieri@gmail.com>
  • Loading branch information
CosmicToast and Guldoman authored Jan 20, 2024
1 parent 8b9b26e commit e9a8dff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/api/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,12 +560,12 @@ static int process_env_add(process_env_t *env_list, size_t *env_len, const char
}


static void process_env_free(process_env_t *list) {
static void process_env_free(process_env_t *list, size_t list_len) {
if (!*list) return;
#ifdef _WIN32
free(*list);
#else
for (size_t i = 0; (*list)[i]; i++) free((*list)[i]);
for (size_t i = 0; i < list_len; i++) free((*list)[i]);
free(*list);
#endif
*list = NULL;
Expand Down Expand Up @@ -830,7 +830,7 @@ static int process_start(lua_State* L) {
}
}
process_arglist_free(&arglist);
process_env_free(&env_vars);
process_env_free(&env_vars, env_vars_len);

if (retval == -1)
return lua_error(L);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ RenWindow* ren_init(SDL_Window *win) {
fprintf(stderr, "internal font error when starting the application\n");
return NULL;
}
RenWindow* window_renderer = malloc(sizeof(RenWindow));
RenWindow* window_renderer = calloc(1, sizeof(RenWindow));

window_renderer->window = win;
renwin_init_surface(window_renderer);
Expand Down

0 comments on commit e9a8dff

Please sign in to comment.