foo = realloc(foo, ...);ret = realloc(foo, ...);
if (ret == NULL) {
// [...] handle error
free(foo);
return ENOMEM;
}
foo = ret;foo = realloc(foo, ...);. On failure, realloc
returns NULL, but leaves the original buffer untouched. So this anti pattern
risks losing the reference to the original buffer, causing a memory leak.sigma star gmbh
Eduard-Bodem-Gasse 6, 1st floor
6020 Innsbruck | Austria