Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
ff3221a3
Commit
ff3221a3
authored
Dec 25, 2016
by
Daniel Cohen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#394 fixed memory leak in unit-allocator, found by clang's fsanitize
parent
010ea126
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
4 deletions
+18
-4
unit-allocator.cpp
test/src/unit-allocator.cpp
+18
-4
No files found.
test/src/unit-allocator.cpp
View file @
ff3221a3
...
@@ -111,6 +111,16 @@ struct my_allocator : std::allocator<T>
...
@@ -111,6 +111,16 @@ struct my_allocator : std::allocator<T>
}
}
};
};
// allows deletion of raw pointer, usually hold by json_value
template
<
class
T
>
void
my_allocator_clean_up
(
T
*
p
)
{
assert
(
p
!=
nullptr
);
my_allocator
<
T
>
alloc
;
alloc
.
destroy
(
p
);
alloc
.
deallocate
(
p
,
1
);
}
TEST_CASE
(
"controlled bad_alloc"
)
TEST_CASE
(
"controlled bad_alloc"
)
{
{
// create JSON type using the throwing allocator
// create JSON type using the throwing allocator
...
@@ -131,7 +141,8 @@ TEST_CASE("controlled bad_alloc")
...
@@ -131,7 +141,8 @@ TEST_CASE("controlled bad_alloc")
{
{
next_construct_fails
=
false
;
next_construct_fails
=
false
;
auto
t
=
my_json
::
value_t
::
object
;
auto
t
=
my_json
::
value_t
::
object
;
CHECK_NOTHROW
(
my_json
::
json_value
j
(
t
));
auto
clean_up
=
[](
my_json
::
json_value
&
j
){
my_allocator_clean_up
(
j
.
object
);
};
CHECK_NOTHROW
(
my_json
::
json_value
j
(
t
);
clean_up
(
j
));
next_construct_fails
=
true
;
next_construct_fails
=
true
;
CHECK_THROWS_AS
(
my_json
::
json_value
j
(
t
),
std
::
bad_alloc
);
CHECK_THROWS_AS
(
my_json
::
json_value
j
(
t
),
std
::
bad_alloc
);
next_construct_fails
=
false
;
next_construct_fails
=
false
;
...
@@ -140,7 +151,8 @@ TEST_CASE("controlled bad_alloc")
...
@@ -140,7 +151,8 @@ TEST_CASE("controlled bad_alloc")
{
{
next_construct_fails
=
false
;
next_construct_fails
=
false
;
auto
t
=
my_json
::
value_t
::
array
;
auto
t
=
my_json
::
value_t
::
array
;
CHECK_NOTHROW
(
my_json
::
json_value
j
(
t
));
auto
clean_up
=
[](
my_json
::
json_value
&
j
){
my_allocator_clean_up
(
j
.
array
);
};
CHECK_NOTHROW
(
my_json
::
json_value
j
(
t
);
clean_up
(
j
));
next_construct_fails
=
true
;
next_construct_fails
=
true
;
CHECK_THROWS_AS
(
my_json
::
json_value
j
(
t
),
std
::
bad_alloc
);
CHECK_THROWS_AS
(
my_json
::
json_value
j
(
t
),
std
::
bad_alloc
);
next_construct_fails
=
false
;
next_construct_fails
=
false
;
...
@@ -149,7 +161,8 @@ TEST_CASE("controlled bad_alloc")
...
@@ -149,7 +161,8 @@ TEST_CASE("controlled bad_alloc")
{
{
next_construct_fails
=
false
;
next_construct_fails
=
false
;
auto
t
=
my_json
::
value_t
::
string
;
auto
t
=
my_json
::
value_t
::
string
;
CHECK_NOTHROW
(
my_json
::
json_value
j
(
t
));
auto
clean_up
=
[](
my_json
::
json_value
&
j
){
my_allocator_clean_up
(
j
.
string
);
};
CHECK_NOTHROW
(
my_json
::
json_value
j
(
t
);
clean_up
(
j
));
next_construct_fails
=
true
;
next_construct_fails
=
true
;
CHECK_THROWS_AS
(
my_json
::
json_value
j
(
t
),
std
::
bad_alloc
);
CHECK_THROWS_AS
(
my_json
::
json_value
j
(
t
),
std
::
bad_alloc
);
next_construct_fails
=
false
;
next_construct_fails
=
false
;
...
@@ -160,7 +173,8 @@ TEST_CASE("controlled bad_alloc")
...
@@ -160,7 +173,8 @@ TEST_CASE("controlled bad_alloc")
{
{
next_construct_fails
=
false
;
next_construct_fails
=
false
;
my_json
::
string_t
v
(
"foo"
);
my_json
::
string_t
v
(
"foo"
);
CHECK_NOTHROW
(
my_json
::
json_value
j
(
v
));
auto
clean_up
=
[](
my_json
::
json_value
&
j
){
my_allocator_clean_up
(
j
.
string
);
};
CHECK_NOTHROW
(
my_json
::
json_value
j
(
v
);
clean_up
(
j
));
next_construct_fails
=
true
;
next_construct_fails
=
true
;
CHECK_THROWS_AS
(
my_json
::
json_value
j
(
v
),
std
::
bad_alloc
);
CHECK_THROWS_AS
(
my_json
::
json_value
j
(
v
),
std
::
bad_alloc
);
next_construct_fails
=
false
;
next_construct_fails
=
false
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment