Fix: valgrind warnings

This commit is contained in:
Dorian Zedler 2022-07-20 13:45:00 +02:00
parent 859be7d54e
commit bb51675a94
Signed by: dorian
GPG Key ID: 989DE36109AFA354
1 changed files with 3 additions and 2 deletions

View File

@ -35,12 +35,13 @@ uint8_t* read_file(const char* path, size_t* size) {
struct sysinfo info;
int r = sysinfo(&info);
if (r != 0 || info.freeram < (unsigned long)statOfFile.st_size * 2) {
if (r != 0 || info.freeram < (unsigned long)(statOfFile.st_blksize *
statOfFile.st_blocks * 2)) {
errno = ENOMEM;
return NULL;
}
uint8_t* data = malloc(statOfFile.st_size);
uint8_t* data = malloc(statOfFile.st_blksize * statOfFile.st_blocks);
if (data == NULL) {
fclose(f);
return NULL;