Skip to content

Commit

Permalink
[chip-tool[darwin-framework-tool] Using ComplexArgument leaks on synt…
Browse files Browse the repository at this point in the history
…ax failure and even on success (#36227)

* [chip-tool[darwin-framework-tool] Using a malformed ComplexArgument may result into a leak

* [chip-tool[darwin-framework-tool] Even on success the ComplexArgument may not be cleared properly

---------

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
vivien-apple and andy31415 authored Oct 24, 2024
1 parent 692983e commit d814ce7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions examples/chip-tool/commands/clusters/ComplexArgument.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,12 @@ class ComplexArgumentParser
// - 11 is the maximum length of a %d (-2147483648, 2147483647)
// - 2 is the length for the "[" and "]" characters.
snprintf(labelWithIndex, sizeof(labelWithIndex), "%.241s[%d]", label, i);
ReturnErrorOnFailure(ComplexArgumentParser::Setup(labelWithIndex, content[i], value[i]));
auto error = ComplexArgumentParser::Setup(labelWithIndex, content[i], value[i]);
if (CHIP_NO_ERROR != error)
{
chip::Platform::MemoryFree(content);
return error;
}
}

request = chip::app::DataModel::List<T>(content, value.size());
Expand Down Expand Up @@ -415,7 +420,14 @@ class TypedComplexArgument : public ComplexArgument
return ComplexArgumentParser::Setup(label, *mRequest, value);
}

void Reset() { *mRequest = T(); }
void Reset()
{
if (mRequest != nullptr)
{
ComplexArgumentParser::Finalize(*mRequest);
*mRequest = T();
}
}

private:
T * mRequest;
Expand Down

0 comments on commit d814ce7

Please sign in to comment.