Skip to content

Commit 5bbc679

Browse files
committed
test: fix memory leaked
1 parent 078ac0d commit 5bbc679

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

tuple/test/array_of_strings_sketch_test.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ TEST_CASE("aos sketch: serialize deserialize", "[tuple_sketch]") {
298298
}
299299

300300
TEST_CASE("aos serde validation", "[tuple_sketch]") {
301+
using aos_alloc = std::allocator<array_of_strings>;
302+
using aos_alloc_traits = std::allocator_traits<aos_alloc>;
301303
default_array_of_strings_serde<> serde_no_validate;
302304
default_array_of_strings_serde<> serde_validate(std::allocator<array_of_strings>(), true);
303305

@@ -359,39 +361,49 @@ TEST_CASE("aos serde validation", "[tuple_sketch]") {
359361
SECTION("stream deserialize: invalid utf8 allowed by default") {
360362
auto arr = make_invalid_array();
361363
auto ss = serialize_to_stream(arr);
362-
array_of_strings result(0, "");
363-
REQUIRE_NOTHROW(serde_no_validate.deserialize(ss, &result, 1));
364-
REQUIRE(result.size() == 1);
365-
REQUIRE(result[0] == std::string("\xC3\x28", 2));
364+
aos_alloc alloc;
365+
auto* result = alloc.allocate(1);
366+
REQUIRE_NOTHROW(serde_no_validate.deserialize(ss, result, 1));
367+
REQUIRE(result->size() == 1);
368+
REQUIRE((*result)[0] == std::string("\xC3\x28", 2));
369+
aos_alloc_traits::destroy(alloc, result);
370+
alloc.deallocate(result, 1);
366371
}
367372

368373
SECTION("stream deserialize: invalid utf8 rejected when validation enabled") {
369374
auto arr = make_invalid_array();
370375
auto ss = serialize_to_stream(arr);
371-
array_of_strings result(0, "");
376+
aos_alloc alloc;
377+
auto* result = alloc.allocate(1);
372378
REQUIRE_THROWS_WITH(
373-
serde_validate.deserialize(ss, &result, 1),
379+
serde_validate.deserialize(ss, result, 1),
374380
Catch::Matchers::Contains("invalid UTF-8")
375381
);
382+
alloc.deallocate(result, 1);
376383
}
377384

378385
SECTION("bytes deserialize: invalid utf8 allowed by default") {
379386
auto arr = make_invalid_array();
380387
auto buf = serialize_to_bytes(arr);
381-
array_of_strings result(0, "");
382-
REQUIRE_NOTHROW(serde_no_validate.deserialize(buf.data(), buf.size(), &result, 1));
383-
REQUIRE(result.size() == 1);
384-
REQUIRE(result[0] == std::string("\xC3\x28", 2));
388+
aos_alloc alloc;
389+
auto* result = alloc.allocate(1);
390+
REQUIRE_NOTHROW(serde_no_validate.deserialize(buf.data(), buf.size(), result, 1));
391+
REQUIRE(result->size() == 1);
392+
REQUIRE((*result)[0] == std::string("\xC3\x28", 2));
393+
aos_alloc_traits::destroy(alloc, result);
394+
alloc.deallocate(result, 1);
385395
}
386396

387397
SECTION("bytes deserialize: invalid utf8 rejected when validation enabled") {
388398
auto arr = make_invalid_array();
389399
auto buf = serialize_to_bytes(arr);
390-
array_of_strings result(0, "");
400+
aos_alloc alloc;
401+
auto* result = alloc.allocate(1);
391402
REQUIRE_THROWS_WITH(
392-
serde_validate.deserialize(buf.data(), buf.size(), &result, 1),
403+
serde_validate.deserialize(buf.data(), buf.size(), result, 1),
393404
Catch::Matchers::Contains("invalid UTF-8")
394405
);
406+
alloc.deallocate(result, 1);
395407
}
396408

397409
SECTION("too many nodes rejected") {

0 commit comments

Comments
 (0)