4 ms·
A lot of code looks like this: int handle = open(file, S_IREAD); if (handle == -1) return false; int size; if (read(handle, &size, sizeof(size)) !
by AnimalMuppet 3y ago
A lot of code looks like this:
int handle = open(file, S_IREAD);
if (handle == -1)
return false;
int size;
if (read(handle, &size, sizeof(size)) != sizeof(size))
{
close(handle);
return false;
}
char *buffer = malloc(size);
if (buffer == null)
{
close(handle);
return false;
}
if (read(handle, buffer, size) != size)
{
close(handle);
free(buffer);
return false;
}
And so on, with the number of things you have to clean up growing as you go further down the function.