fix tsearch to avoid crash on oom
authorSzabolcs Nagy <nsz@port70.net>
Sat, 5 Dec 2015 20:04:18 +0000 (21:04 +0100)
committerRich Felker <dalias@aerifal.cx>
Tue, 8 Dec 2015 23:52:38 +0000 (18:52 -0500)
malloc failure was not properly propagated in the insertion method
which led to null pointer dereference.

src/search/tsearch_avl.c

index 08644607abf5192dde18342c493c6f98cd914ecb..8c2f3470ae492f25fc196476fba93fc6376c6430 100644 (file)
@@ -89,8 +89,8 @@ static struct node *insert(struct node **n, const void *k,
                        r->key = k;
                        r->left = r->right = 0;
                        r->height = 1;
+                       *new = 1;
                }
-               *new = 1;
                return r;
        }
        c = cmp(k, r->key);