diff --git a/desmume/src/cflash.cpp b/desmume/src/cflash.cpp index 2171c5ea6..fe3d0c856 100644 --- a/desmume/src/cflash.cpp +++ b/desmume/src/cflash.cpp @@ -315,9 +315,13 @@ static BOOL cflash_build_fat( void) { sRomPath = szRomPath; // From MMU.cpp files = (DIR_ENT *) malloc(MAXFILES*sizeof(DIR_ENT)); + if (files == NULL) + return FALSE; fileLink = (FILE_INFO *) malloc(MAXFILES*sizeof(FILE_INFO)); - if ((files == NULL) || (fileLink == NULL)) + if (fileLink == NULL) { + free(files); return FALSE; + } for (i=0; idir = tmp; strcpy(entry->cFileName, e->d_name); diff --git a/desmume/src/gdbstub/gdbstub.cpp b/desmume/src/gdbstub/gdbstub.cpp index 41c40c2d1..20f4c5800 100644 --- a/desmume/src/gdbstub/gdbstub.cpp +++ b/desmume/src/gdbstub/gdbstub.cpp @@ -1440,11 +1440,12 @@ gdbstub_handle_t createStub_gdb( uint16_t port, struct armcpu_memory_iface **cpu_memio, struct armcpu_memory_iface *direct_memio) { - struct gdb_stub_state *stub = (gdb_stub_state*)malloc( sizeof (struct gdb_stub_state)); + struct gdb_stub_state *stub; gdbstub_handle_t handle = NULL; int i; int res = 0; + stub = (gdb_stub_state*)malloc( sizeof (struct gdb_stub_state)); if ( stub == NULL) { return NULL; } diff --git a/desmume/src/matrix.cpp b/desmume/src/matrix.cpp index bd1b2f4e2..ceacdc3c3 100644 --- a/desmume/src/matrix.cpp +++ b/desmume/src/matrix.cpp @@ -158,19 +158,14 @@ void MatrixStackInit (MatrixStack *stack) void MatrixStackSetMaxSize (MatrixStack *stack, int size) { - int i = 0; + int i; stack->size = size; - if (stack->matrix == NULL) - { - stack->matrix = (float*) malloc (stack->size*16*sizeof(float)); - } - else - { + if (stack->matrix != NULL) { free (stack->matrix); - stack->matrix = (float*) malloc (stack->size*16*sizeof(float)); } + stack->matrix = (float*) malloc (stack->size*16*sizeof(float)); for (i = 0; i < stack->size; i++) {