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

View file

@ -35,12 +35,13 @@ uint8_t* read_file(const char* path, size_t* size) {
struct sysinfo info; struct sysinfo info;
int r = 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; errno = ENOMEM;
return NULL; return NULL;
} }
uint8_t* data = malloc(statOfFile.st_size); uint8_t* data = malloc(statOfFile.st_blksize * statOfFile.st_blocks);
if (data == NULL) { if (data == NULL) {
fclose(f); fclose(f);
return NULL; return NULL;