diff --git a/src/tree/insert.c b/src/tree/insert.c index 6f8ffb5..5f95ada 100644 --- a/src/tree/insert.c +++ b/src/tree/insert.c @@ -44,13 +44,14 @@ TR_treeInsert(TR_Tree * this, const void * search, TR_TreeComp comp) TR_TREE_FIND(node, search, found, comp); if (found == 0) { - // we found an element - // as this is insert and not find this will overwrite an existing - // value, but return the previous one so that it can be freed if - // neccessary. - void * data = node->data; - node->data = (void *)search; - return data; + // This differs from tsearch, which is the posix equivalent to + // this function in that it will not replace an existing value. + // If there is a value for the given key in the tree it will be + // retured. It is then up to the caller to handle the situation. + // This is used in my http header code to handle multiple value + // per header. There it is more useful to get the already existing + // tree entry and add the new data. + return node->data; } else { // not found if (0 < found) {