fix: use after free, ISO C warning

This commit is contained in:
2024-01-19 16:05:02 +01:00
parent 9e00c94677
commit 6fa6d7145f
3 changed files with 8 additions and 5 deletions

View File

@@ -17,25 +17,25 @@ int init_state() {
memset(state->registers, 0, sizeof(s_registers));
state->args = malloc(sizeof(s_arguments));
if (state->args == NULL) {
free(state);
free(state->registers);
free(state);
return 1;
}
state->args->arg1 = malloc(sizeof(char) * MAX_ARG_SIZE);
state->args->arg2 = malloc(sizeof(char) * MAX_ARG_SIZE);
if (state->args->arg1 == NULL || state->args->arg2 == NULL) {
free(state);
free(state->registers);
free(state);
return 1;
}
memset(state->args->arg1, 0, sizeof(char) * MAX_ARG_SIZE);
memset(state->args->arg2, 0, sizeof(char) * MAX_ARG_SIZE);
state->labels_values = malloc(sizeof(int) * MAX_LABELS);
if (state->labels_values == NULL) {
free(state);
free(state->registers);
free(state->args->arg1);
free(state->args->arg2);
free(state);
return 1;
}
memset(state->labels_values, 0, sizeof(int) * MAX_LABELS);

View File

@@ -1,6 +1,8 @@
#include "fmemopen.h"
typedef int make_iso_compilers_happy; //...
#ifdef _WIN32
#include <windows.h>
#include "fmemopen.h"
#include <share.h>
#include <io.h>
#include <fcntl.h>

View File

@@ -1,5 +1,6 @@
#ifdef _WIN32
#pragma once
#ifdef _WIN32
#include <stdio.h>
FILE *fmemopen(void *buf, size_t len, const char *type);
#endif