diff --git a/CMakeLists.txt b/CMakeLists.txt index b97f9b3..b4d0730 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # CMake entry point -cmake_minimum_required (VERSION 3.30.5) +cmake_minimum_required(VERSION 3.31.0) project(CX C) cmake_policy(SET CMP0072 NEW) @@ -20,7 +20,7 @@ set(ALL_LIBS pthread ) -set(CMAKE_C_FLAGS "-O0 -ggdb -Wall") +set(CMAKE_C_FLAGS "-O0 -ggdb -Wall -std=gnu99 -Wpedantic") add_definitions( -DTW_STATIC diff --git a/src/cx.c b/src/cx.c index c8e07dd..e013925 100644 --- a/src/cx.c +++ b/src/cx.c @@ -185,22 +185,42 @@ cx_init(CX_Context **cx_ctx) { *cx_ctx = calloc(1, sizeof(CX_Context)); (*cx_ctx)->VertexArrayIDs = calloc(1, sizeof(GLuint)); + if (!(*cx_ctx)->VertexArrayIDs) { + goto err; + } (*cx_ctx)->VertexArray_count = 0; (*cx_ctx)->VertexArray_size = 1; (*cx_ctx)->programIDs = calloc(1, sizeof(GLuint)); + if (!(*cx_ctx)->programIDs) { + goto err; + } (*cx_ctx)->ProgramID_count = 0; (*cx_ctx)->ProgramID_size = 1; (*cx_ctx)->threads = calloc(1, sizeof(CX_ThreadGroup)); + if (!(*cx_ctx)->threads) { + goto err; + } if (cx_glinit(&(*cx_ctx)->window)) { - return -1; + goto err; } if (cx_nninit(&(*cx_ctx)->nn)) { - return -1; + goto err; } return 0; + +err: + if (*cx_ctx) { + free((*cx_ctx)->VertexArrayIDs); + free((*cx_ctx)->programIDs); + free((*cx_ctx)->threads); + } + + free(*cx_ctx); + + return -1; } static int diff --git a/src/main.c b/src/main.c index 01ef0d8..9d5f21e 100644 --- a/src/main.c +++ b/src/main.c @@ -7,7 +7,6 @@ main(void) { int retval; - if (cx_init(&cx_ctx)) { return -1; }