Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Xin Wang
codes-dev
Commits
bad3fec3
Commit
bad3fec3
authored
Aug 28, 2015
by
Jonathan Jenkins
Browse files
fix rc-stack memory leak in sequential
parent
1de8c287
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/util/rc-stack.c
View file @
bad3fec3
...
...
@@ -18,6 +18,7 @@ typedef struct rc_entry_s {
struct
rc_stack
{
int
count
;
int
is_in_optimistic
;
struct
qlist_head
head
;
};
...
...
@@ -27,6 +28,7 @@ void rc_stack_create(struct rc_stack **s){
INIT_QLIST_HEAD
(
&
ss
->
head
);
ss
->
count
=
0
;
}
ss
->
is_in_optimistic
=
(
g_tw_synchronization_protocol
==
OPTIMISTIC
);
*
s
=
ss
;
}
...
...
@@ -40,13 +42,17 @@ void rc_stack_push(
void
*
data
,
void
(
*
free_fn
)(
void
*
),
struct
rc_stack
*
s
){
rc_entry
*
ent
=
(
rc_entry
*
)
malloc
(
sizeof
(
*
ent
));
assert
(
ent
);
ent
->
time
=
tw_now
(
lp
);
ent
->
data
=
data
;
ent
->
free_fn
=
free_fn
;
qlist_add_tail
(
&
ent
->
ql
,
&
s
->
head
);
s
->
count
++
;
if
(
s
->
is_in_optimistic
||
free_fn
==
NULL
)
{
rc_entry
*
ent
=
(
rc_entry
*
)
malloc
(
sizeof
(
*
ent
));
assert
(
ent
);
ent
->
time
=
tw_now
(
lp
);
ent
->
data
=
data
;
ent
->
free_fn
=
free_fn
;
qlist_add_tail
(
&
ent
->
ql
,
&
s
->
head
);
s
->
count
++
;
}
else
free_fn
(
data
);
}
void
*
rc_stack_pop
(
struct
rc_stack
*
s
){
...
...
tests/rc-stack-test.c
View file @
bad3fec3
...
...
@@ -21,6 +21,8 @@ int main(int argc, char *argv[])
lp
.
pe
=
&
pe
;
lp
.
kp
=
&
kp
;
g_tw_synchronization_protocol
=
OPTIMISTIC
;
struct
rc_stack
*
s
;
rc_stack_create
(
&
s
);
assert
(
s
!=
NULL
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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