Permalink
Browse files

Use xmalloc instead of malloc

  • Loading branch information...
1 parent cb95ad7 commit 2c89c9b7a4f189a98bdbcf81710643ed45474a65 @kanwei committed May 16, 2013
@@ -26,7 +26,7 @@ long levenshtein_distance(VALUE str1, VALUE str2) {
s1_len++;
s2_len++;
- d = malloc(sizeof(typeof(d)) * (s1_len) * (s2_len));
+ d = xmalloc(sizeof(typeof(d)) * s1_len * s2_len);
for (i = 0; i < s1_len; i++) {
d[i] = i; // d[i, 0] = i
@@ -49,7 +49,7 @@ long levenshtein_distance(VALUE str1, VALUE str2) {
}
}
i = d[s1_len * s2_len -1];
- free(d);
+ xfree(d);
return i;
}
View
@@ -172,7 +172,7 @@ static void recursively_free_nodes(bst_node *node) {
if(node) {
recursively_free_nodes(node->left);
recursively_free_nodes(node->right);
- free(node);
+ xfree(node);
}
}
@@ -19,7 +19,7 @@ void free_nodes(deque_node *node) {
deque_node *next;
while(node) {
next = node->right;
- free(node);
+ xfree(node);
node = next;
}
return;
@@ -71,7 +71,7 @@ static void deque_free(void *ptr) {
if (ptr) {
deque *deque = ptr;
free_nodes(deque->front);
- free(deque);
+ xfree(deque);
}
}
@@ -31,7 +31,7 @@ static void recursively_free_nodes(rbtree_node *node) {
if(node) {
recursively_free_nodes(node->left);
recursively_free_nodes(node->right);
- free(node);
+ xfree(node);
}
return;
}
@@ -198,7 +198,7 @@ static rbtree_node* delete_min(rbtree_node *h, VALUE *deleted_value) {
if ( !h->left ) {
if(deleted_value)
*deleted_value = h->value;
- free(h);
+ xfree(h);
return NULL;
}
@@ -216,7 +216,7 @@ static rbtree_node* delete_max(rbtree_node *h, VALUE *deleted_value) {
if ( !h->right ) {
*deleted_value = h->value;
- free(h);
+ xfree(h);
return NULL;
}
@@ -245,7 +245,7 @@ static rbtree_node* delete(rbtree *tree, rbtree_node *node, VALUE key, VALUE *de
cmp = tree->compare_function(key, node->key);
if ( (cmp == 0) && !node->right ) {
*deleted_value = node->value;
- free(node);
+ xfree(node);
return NULL;
}
@@ -339,7 +339,7 @@ static void rbtree_mark(void *ptr) {
}
old = current;
current = current->next;
- free(old);
+ xfree(old);
}
}
}
@@ -349,7 +349,7 @@ static void rbtree_free(void *ptr) {
if (ptr) {
rbtree *tree = ptr;
recursively_free_nodes(tree->root);
- free(tree);
+ xfree(tree);
}
}
@@ -28,7 +28,7 @@ static void recursively_free_nodes(splaytree_node *node) {
if(node) {
recursively_free_nodes(node->left);
recursively_free_nodes(node->right);
- free(node);
+ xfree(node);
}
return;
}
@@ -199,7 +199,7 @@ static splaytree_node* delete(splaytree *tree, splaytree_node *n, VALUE key, VAL
x = splay(tree, n->left, key);
x->right = n->right;
}
- free(n);
+ xfree(n);
if (x) {
x->size = tsize-1;
}
@@ -282,7 +282,7 @@ static void splaytree_mark(void *ptr) {
}
old = current;
current = current->next;
- free(old);
+ xfree(old);
}
}
}
@@ -292,7 +292,7 @@ static void splaytree_free(void *ptr) {
if (ptr) {
splaytree *tree = ptr;
recursively_free_nodes(tree->root);
- free(tree);
+ xfree(tree);
}
}

0 comments on commit 2c89c9b

Please sign in to comment.