Fix bugs pointed out by valgrind

This commit is contained in:
MysterD 2022-02-20 22:06:53 -08:00
parent c2ee370182
commit 660e787502
5 changed files with 17 additions and 9 deletions

View File

@ -176,10 +176,10 @@ extern struct Camera *gCamera;
* Lakitu's position and focus.
* @see LakituState
*/
struct LakituState gLakituState;
struct CameraFOVStatus sFOVState;
struct TransitionInfo sModeTransition;
struct PlayerGeometry sMarioGeometry;
struct LakituState gLakituState = { 0 };
struct CameraFOVStatus sFOVState = { 0 };
struct TransitionInfo sModeTransition = { 0 };
struct PlayerGeometry sMarioGeometry = { 0 };
struct Camera *gCamera;
s16 unusedFreeRoamWallYaw;
s16 sAvoidYawVel;

View File

@ -298,8 +298,10 @@ void configfile_load(const char *filename) {
while (isspace(*p))
p++;
if (!*p || *p == '#') // comment or empty line
if (!*p || *p == '#') { // comment or empty line
free(line);
continue;
}
numTokens = tokenize_string(p, sizeof(tokens) / sizeof(tokens[0]), tokens);
if (numTokens != 0) {
@ -315,12 +317,14 @@ void configfile_load(const char *filename) {
break;
}
}
free(line);
continue;
}
// ban list
if (!strcmp(tokens[0], "ban:")) {
ban_list_add(tokens[1], true);
free(line);
continue;
}

View File

@ -7,9 +7,11 @@
static void _debuglog_print_timestamp(void) {
time_t ltime = time(NULL);
char* str = asctime(localtime(&ltime));
struct tm ltime2 = { 0 };
localtime_r(&ltime, &ltime2);
char* str = asctime(&ltime2);
printf("%.*s", (int)strlen(str) - 1, str);
}
}
static void _debuglog_print_network_type(void) {
printf(" [%02d] ", (gNetworkPlayerLocal != NULL) ? gNetworkPlayerLocal->globalIndex : -1);

View File

@ -26,7 +26,9 @@ void logfile_close(enum LogFileType logFileType);
static void _logfile_print_timestamp(enum LogFileType logFileType) {
FILE* f = gLogFiles[logFileType].file;
time_t ltime = time(NULL);
char* str = asctime(localtime(&ltime));
struct tm ltime2 = { 0 };
localtime_r(&ltime, &ltime2);
char* str = asctime(&ltime2);
fprintf(f, "%.*s", (int)strlen(str) - 1, str);
}

View File

@ -232,7 +232,7 @@ void main_func(void) {
configWindow.fullscreen = false;
const size_t poolsize = gCLIOpts.PoolSize ? gCLIOpts.PoolSize : DEFAULT_POOL_SIZE;
u64 *pool = malloc(poolsize);
u64 *pool = calloc(poolsize, 1);
if (!pool) sys_fatal("Could not alloc %u bytes for main pool.\n", poolsize);
main_pool_init(pool, pool + poolsize / sizeof(pool[0]));
gEffectsMemoryPool = mem_pool_init(0x4000, MEMORY_POOL_LEFT);