Skip to content

Commit 517b4da

Browse files
aalkinclaude
andcommitted
Do not leak frames in TestWSHandler
TestWSHandler stored strdup'ed copies of every frame and never freed them. Keep the frames in a std::vector<std::string> instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent be01fc2 commit 517b4da

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

‎Framework/Core/test/test_HTTPParser.cxx‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ class DPLClientParser : public HTTPParser
8080
class TestWSHandler : public WebSocketHandler
8181
{
8282
public:
83-
std::vector<char const*> mFrame;
83+
std::vector<std::string> mFrame;
8484
std::vector<size_t> mSize;
8585
void frame(const char* f, size_t s) final
8686
{
87-
mFrame.push_back(strdup(f));
88-
mSize.push_back(s);
87+
mFrame.emplace_back(f, s);
88+
mSize.emplace_back(s);
8989
}
9090
};
9191

@@ -187,7 +187,7 @@ TEST_CASE("HTTPParser1")
187187
; // 1 for the 0, 2 for the header
188188
decode_websocket(encoded[0].base, encoded[0].len, handler);
189189
REQUIRE(handler.mSize[0] == strlen(buffer) + 1);
190-
REQUIRE(std::string(handler.mFrame[0], handler.mSize[0] - 1) == std::string(buffer));
190+
REQUIRE(handler.mFrame[0].substr(0, handler.mSize[0] - 1) == std::string(buffer));
191191
}
192192
{
193193
// WebSocket multiple frame encoding / decoding
@@ -214,8 +214,8 @@ TEST_CASE("HTTPParser1")
214214
decode_websocket(multiBuffer, encoded[0].len + encoded[1].len, handler);
215215
REQUIRE(handler.mFrame.size() == 2);
216216
REQUIRE(handler.mSize.size() == 2);
217-
REQUIRE(std::string(handler.mFrame[0], handler.mSize[0] - 1) == std::string(buffer));
218-
REQUIRE(std::string(handler.mFrame[1], handler.mSize[1] - 1) == std::string(buffer2));
217+
REQUIRE(handler.mFrame[0].substr(0, handler.mSize[0] - 1) == std::string(buffer));
218+
REQUIRE(handler.mFrame[1].substr(0, handler.mSize[1] - 1) == std::string(buffer2));
219219
}
220220
{
221221
// Decode a frame which is split in two.
@@ -229,7 +229,7 @@ TEST_CASE("HTTPParser1")
229229
decode_websocket(encoded[0].base + encoded[0].len / 2, encoded[0].len - encoded[0].len / 2, handler);
230230
REQUIRE(handler.mFrame.size() == 1);
231231
REQUIRE(handler.mSize.size() == 1);
232-
REQUIRE(std::string(handler.mFrame[0], handler.mSize[0] - 1) == std::string(buffer));
232+
REQUIRE(handler.mFrame[0].substr(0, handler.mSize[0] - 1) == std::string(buffer));
233233
}
234234
{
235235
// Decode a long frame which is split in two.
@@ -243,7 +243,7 @@ TEST_CASE("HTTPParser1")
243243
decode_websocket(encoded[0].base + encoded[0].len / 2, encoded[0].len - encoded[0].len / 2, handler);
244244
REQUIRE(handler.mFrame.size() == 1);
245245
REQUIRE(handler.mSize.size() == 1);
246-
REQUIRE(std::string(handler.mFrame[0], handler.mSize[0] - 1) == std::string(buffer));
246+
REQUIRE(handler.mFrame[0].substr(0, handler.mSize[0] - 1) == std::string(buffer));
247247
}
248248
{
249249
// WebSocket multiple frame encoding / decoding, long frames
@@ -259,8 +259,8 @@ TEST_CASE("HTTPParser1")
259259
decode_websocket(encoded[0].base, encoded[0].len, handler);
260260
REQUIRE(handler.mFrame.size() == 2);
261261
REQUIRE(handler.mSize.size() == 2);
262-
REQUIRE(std::string(handler.mFrame[0], handler.mSize[0] - 1) == std::string(buffer));
263-
REQUIRE(std::string(handler.mFrame[1], handler.mSize[1] - 1) == std::string(buffer2));
262+
REQUIRE(handler.mFrame[0].substr(0, handler.mSize[0] - 1) == std::string(buffer));
263+
REQUIRE(handler.mFrame[1].substr(0, handler.mSize[1] - 1) == std::string(buffer2));
264264
}
265265
{
266266
// Decode a long frame which is split in two, after the first byte.
@@ -281,7 +281,7 @@ TEST_CASE("HTTPParser1")
281281
decode_websocket(buffer2, encoded[0].len - i, handler);
282282
REQUIRE(handler.mFrame.size() == 1);
283283
REQUIRE(handler.mSize.size() == 1);
284-
REQUIRE(std::string(handler.mFrame[0], handler.mSize[0] - 1) == std::string(buffer));
284+
REQUIRE(handler.mFrame[0].substr(0, handler.mSize[0] - 1) == std::string(buffer));
285285
}
286286
}
287287
{
@@ -310,7 +310,7 @@ TEST_CASE("HTTPParser1")
310310
decode_websocket(buffer3, encoded[0].len - j, handler);
311311
REQUIRE(handler.mFrame.size() == 1);
312312
REQUIRE(handler.mSize.size() == 1);
313-
REQUIRE(std::string(handler.mFrame[0], handler.mSize[0] - 1) == std::string(buffer));
313+
REQUIRE(handler.mFrame[0].substr(0, handler.mSize[0] - 1) == std::string(buffer));
314314
}
315315
}
316316
}

0 commit comments

Comments
 (0)