From be1225324321b0bf7279b122f7df2b6838751539 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 12 Sep 2014 00:30:53 -0400 Subject: [PATCH] Fix some more possible null pointer dereferences --- frontend/menu/disp/rgui.c | 12 ++++++++++-- gfx/d3d9/d3d_shared.h | 6 +++++- gfx/d3d9/render_chain_cg.h | 3 +++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/frontend/menu/disp/rgui.c b/frontend/menu/disp/rgui.c index 276278fc3b..5316a453bc 100644 --- a/frontend/menu/disp/rgui.c +++ b/frontend/menu/disp/rgui.c @@ -145,10 +145,17 @@ static void blit_line(int x, int y, const char *message, bool green) } } -static void init_font(menu_handle_t *menu, const uint8_t *font_bmp_buf) +static bool init_font(menu_handle_t *menu, const uint8_t *font_bmp_buf) { unsigned i; uint8_t *font = (uint8_t *) calloc(1, FONT_OFFSET(256)); + + if (!font) + { + RARCH_ERR("Font memory allocation failed in %s", __FUNCTION__); + return false; + } + menu->alloc_font = true; for (i = 0; i < 256; i++) { @@ -159,6 +166,7 @@ static void init_font(menu_handle_t *menu, const uint8_t *font_bmp_buf) } menu->font = font; + return true; } static bool rguidisp_init_font(void *data) @@ -169,7 +177,7 @@ static bool rguidisp_init_font(void *data) const uint8_t *font_bin_buf = bitmap_bin; if (font_bmp_buf) - init_font(menu, font_bmp_buf); + return init_font(menu, font_bmp_buf); else if (font_bin_buf) menu->font = font_bin_buf; else diff --git a/gfx/d3d9/d3d_shared.h b/gfx/d3d9/d3d_shared.h index 8b8e8b8ea7..8f708b729f 100644 --- a/gfx/d3d9/d3d_shared.h +++ b/gfx/d3d9/d3d_shared.h @@ -434,6 +434,10 @@ static bool d3d_construct(d3d_video_t *d3d, free(d3d->menu); d3d->menu = (overlay_t*)calloc(1, sizeof(overlay_t)); + + if (!d3d->menu) + return false; + d3d->menu->tex_coords.x = 0; d3d->menu->tex_coords.y = 0; d3d->menu->tex_coords.w = 1; @@ -630,7 +634,7 @@ static void *d3d_init(const video_info_t *info, vid->ctx_driver = d3d_get_context(vid); if (!vid->ctx_driver) { - free(vid); + delete vid; return NULL; } diff --git a/gfx/d3d9/render_chain_cg.h b/gfx/d3d9/render_chain_cg.h index 9daf559f2d..91d9c97a96 100644 --- a/gfx/d3d9/render_chain_cg.h +++ b/gfx/d3d9/render_chain_cg.h @@ -40,6 +40,9 @@ static inline bool validate_param_name(const char *name) "PASS", }; + if (!name) + return false; + for (unsigned i = 0; i < sizeof(illegal) / sizeof(illegal[0]); i++) if (strstr(name, illegal[i]) == name) return false;