diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-09-20 18:43:19 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-09-21 15:22:27 -0700 |
commit | 79f22da9c87d295bd39ea24250c2d64df8110cc9 (patch) | |
tree | 01af7450569d59e8e03129c5ed9f5f7c2f5189a1 /ext/rpatricia/rpatricia.c | |
parent | 489db03a546b3ee41760f1ee8d662fba81299b60 (diff) | |
download | rpatricia-79f22da9c87d295bd39ea24250c2d64df8110cc9.tar.gz |
fix segfault from unpredictable GC ordering
We cannot guarantee GC will mark valid nodes when the tree the node belongs to is destroyed, so we have to allocate a new node that is a copy of the original node whenever we create Patricia::Node objects
Diffstat (limited to 'ext/rpatricia/rpatricia.c')
-rw-r--r-- | ext/rpatricia/rpatricia.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/ext/rpatricia/rpatricia.c b/ext/rpatricia/rpatricia.c index 1c81ba1..ae018af 100644 --- a/ext/rpatricia/rpatricia.c +++ b/ext/rpatricia/rpatricia.c @@ -33,10 +33,13 @@ p_node_mark (void *ptr) } static VALUE -wrap_node(patricia_node_t *node) +wrap_node(patricia_node_t *orig) { - /* node will be freed when parent is freed */ - return Data_Wrap_Struct(cNode, p_node_mark, 0, node); + patricia_node_t *node = ALLOC(patricia_node_t); + + memcpy(node, orig, sizeof(patricia_node_t)); + + return Data_Wrap_Struct(cNode, p_node_mark, -1, node); } static prefix_t * |