Browse Source

lub.list: Fix memory leak

Serj Kalichev 4 years ago
parent
commit
cae653df0c
2 changed files with 6 additions and 1 deletions
  1. 0 1
      clish/ptype/ptype.c
  2. 6 0
      lub/list/list.c

+ 0 - 1
clish/ptype/ptype.c

@@ -229,7 +229,6 @@ clish_ptype_method_e clish_ptype_method_resolve(const char *name)
 		if (!strcmp(name, method_names[i]))
 			break;
 	}
-
 	return (clish_ptype_method_e)i;
 }
 

+ 6 - 0
lub/list/list.c

@@ -57,6 +57,9 @@ void lub_list_free_all(lub_list_t *this)
 /*--------------------------------------------------------- */
 inline lub_list_node_t *lub_list__get_head(lub_list_t *this)
 {
+	assert(this);
+	if (!this)
+		return NULL;
 	return this->head;
 }
 
@@ -164,6 +167,7 @@ static lub_list_node_t *lub_list_add_generic(lub_list_t *this, void *data,
 		int res = this->compareFn(node->data, iter->data);
 		if (uniq && (res == 0)) {
 			this->len--; // Revert previous increment
+			lub_list_node_free(node);
 			return (find ? iter : NULL);
 		}
 		if (res >= 0) {
@@ -218,6 +222,8 @@ void lub_list_del(lub_list_t *this, lub_list_node_t *node)
 		node->next->prev = node->prev;
 	else
 		this->tail = node->prev;
+	node->prev = NULL;
+	node->next = NULL;
 
 	this->len--;
 }