From: Szabolcs Nagy <nsz@port70.net>
Date: Sat, 5 Dec 2015 20:04:18 +0000 (+0100)
Subject: fix tsearch to avoid crash on oom
X-Git-Tag: v1.1.13~112
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bc9744763afe72d626e7b9f461001d425582fe9c;p=musl

fix tsearch to avoid crash on oom

malloc failure was not properly propagated in the insertion method
which led to null pointer dereference.
---

diff --git a/src/search/tsearch_avl.c b/src/search/tsearch_avl.c
index 08644607..8c2f3470 100644
--- a/src/search/tsearch_avl.c
+++ b/src/search/tsearch_avl.c
@@ -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);