Skip to content
Myr

stb_image: fixed 'out' nulled but not freed upon failure

Before adoption: this commit came in with the history the project adopted, so no landing records it.

If realloc fails it returns NULL and out pointer becomes invalid. To fix this it is necessary to store realloc return value in temporary pointer and then compare it with NULL. If it equals NULL then return error and source pointer will still valid. This error was caught by cppcheck: Common realloc mistake: 'out' nulled but not freed upon failure.

authored by Georgy Macharadze · committed by Georgy Macharadze · parent 72990ef · Browse files · 1 file+9 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+9 added−1 removed

  • other:+9 added−1 removed

1 file+9 added−1 removed

modified:stb_image.h+9 added-1 removed
6587 unmodified lines
6588 ++layers; 6589 stride = g.w * g.h * 4; 6590 6591 if (out) {6592 out = (stbi_uc*) STBI_REALLOC( out, layers * stride ); 6592 void *tmp = (stbi_uc*) STBI_REALLOC( out, layers * stride );6593 if (NULL == tmp) {6594 STBI_FREE(g.out);6595 STBI_FREE(g.history);6596 STBI_FREE(g.background);6597 return stbi__errpuc("outofmem", "Out of memory");6598 }6599 else6600 out = tmp;6601 if (delays) {6602 *delays = (int*) STBI_REALLOC( *delays, sizeof(int) * layers ); 6603 }6604 } else {
934 unmodified lines