Fix bugs; better handle oplevels from ircu2.10.12
[srvx.git] / src / dict-splay.c
index 3a6cafd7f28bfcf8b3f048cdc4436a69a9f03234..42bb9025778342b5107b190ee4f70cc0ac04b55c 100644 (file)
@@ -1,19 +1,17 @@
 /* dict-splay.c - Abstract dictionary type
  * Copyright 2000-2004 srvx Development Team
  *
- * This program is free software; you can redistribute it and/or modify
+ * This file is part of srvx.
+ *
+ * srvx is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.  Important limitations are
- * listed in the COPYING file that accompanies this software.
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, email srvx-maintainers@srvx.net.
  */
 
 #include "common.h"
@@ -204,7 +202,7 @@ dict_insert(dict_t dict, const char *key, void *data)
 int
 dict_remove2(dict_t dict, const char *key, int no_dispose)
 {
-    struct dict_node *new_root;
+    struct dict_node *new_root, *old_root;
 
     if (!dict->root)
         return 0;
@@ -222,13 +220,14 @@ dict_remove2(dict_t dict, const char *key, int no_dispose)
     if (dict->first == dict->root) dict->first = dict->first->next;
     if (dict->root->next) dict->root->next->prev = dict->root->prev;
     if (dict->last == dict->root) dict->last = dict->last->prev;
+    old_root = dict->root;
+    dict->root = new_root;
+    dict->count--;
     if (no_dispose) {
-        free(dict->root);
+        free(old_root);
     } else {
-        dict_dispose_node(dict->root, dict->free_keys, dict->free_data);
+        dict_dispose_node(old_root, dict->free_keys, dict->free_data);
     }
-    dict->root = new_root;
-    dict->count--;
     return 1;
 }