Commit bad3fec3 authored by Jonathan Jenkins's avatar Jonathan Jenkins

fix rc-stack memory leak in sequential

parent 1de8c287
...@@ -18,6 +18,7 @@ typedef struct rc_entry_s { ...@@ -18,6 +18,7 @@ typedef struct rc_entry_s {
struct rc_stack { struct rc_stack {
int count; int count;
int is_in_optimistic;
struct qlist_head head; struct qlist_head head;
}; };
...@@ -27,6 +28,7 @@ void rc_stack_create(struct rc_stack **s){ ...@@ -27,6 +28,7 @@ void rc_stack_create(struct rc_stack **s){
INIT_QLIST_HEAD(&ss->head); INIT_QLIST_HEAD(&ss->head);
ss->count = 0; ss->count = 0;
} }
ss->is_in_optimistic = (g_tw_synchronization_protocol == OPTIMISTIC);
*s = ss; *s = ss;
} }
...@@ -40,13 +42,17 @@ void rc_stack_push( ...@@ -40,13 +42,17 @@ void rc_stack_push(
void * data, void * data,
void (*free_fn)(void*), void (*free_fn)(void*),
struct rc_stack *s){ struct rc_stack *s){
rc_entry * ent = (rc_entry*)malloc(sizeof(*ent)); if (s->is_in_optimistic || free_fn == NULL) {
assert(ent); rc_entry * ent = (rc_entry*)malloc(sizeof(*ent));
ent->time = tw_now(lp); assert(ent);
ent->data = data; ent->time = tw_now(lp);
ent->free_fn = free_fn; ent->data = data;
qlist_add_tail(&ent->ql, &s->head); ent->free_fn = free_fn;
s->count++; qlist_add_tail(&ent->ql, &s->head);
s->count++;
}
else
free_fn(data);
} }
void* rc_stack_pop(struct rc_stack *s){ void* rc_stack_pop(struct rc_stack *s){
......
...@@ -21,6 +21,8 @@ int main(int argc, char *argv[]) ...@@ -21,6 +21,8 @@ int main(int argc, char *argv[])
lp.pe = &pe; lp.pe = &pe;
lp.kp = &kp; lp.kp = &kp;
g_tw_synchronization_protocol = OPTIMISTIC;
struct rc_stack *s; struct rc_stack *s;
rc_stack_create(&s); rc_stack_create(&s);
assert(s != NULL); assert(s != NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment