mirror of
https://github.com/libexpat/libexpat.git
synced 2025-04-09 22:47:48 +00:00
examples/element_declarations.c: Fix memleak in dumpContentModel on OOM
clang-tidy output was: > [..]/examples/element_declarations.c:163:16: warning: Potential leak of memory pointed to by 'stackTop' [clang-analyzer-unix.Malloc] > 163 | return false; > | ^
This commit is contained in:
parent
716fd10bd4
commit
0ebca2b10f
1 changed files with 8 additions and 2 deletions
|
@ -157,11 +157,17 @@ dumpContentModel(const XML_Char *name, const XML_Content *root) {
|
|||
stackTop = stackPopFree(stackTop);
|
||||
|
||||
for (size_t u = model->numchildren; u >= 1; u--) {
|
||||
stackTop
|
||||
Stack *const newStackTop
|
||||
= stackPushMalloc(stackTop, model->children + (u - 1), level + 1);
|
||||
if (! stackTop) {
|
||||
if (! newStackTop) {
|
||||
// We ran out of memory, so let's free all memory allocated
|
||||
// earlier in this function, to be leak-clean:
|
||||
while (stackTop != NULL) {
|
||||
stackTop = stackPopFree(stackTop);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
stackTop = newStackTop;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue