diff options
| author | Tucker Evans <tucker@tuckerevans.com> | 2020-07-06 11:09:27 -0400 | 
|---|---|---|
| committer | Tucker Evans <tucker@tuckerevans.com> | 2020-07-06 11:09:27 -0400 | 
| commit | e1f7e38d660e46b1e32455595c4829f294a2740b (patch) | |
| tree | c7babfa7822c3f75bd15f512dc11d05a9fa2f192 /collections/double_ended_queue/double_ended_queue.c | |
| parent | a7dda0e0060d868c8a797b5a05b64d1aa09548d7 (diff) | |
Fix double ended queue remove
Did not return the removed object, could easily lead to a memory leak.
Diffstat (limited to 'collections/double_ended_queue/double_ended_queue.c')
| -rw-r--r-- | collections/double_ended_queue/double_ended_queue.c | 5 | 
1 files changed, 5 insertions, 0 deletions
| diff --git a/collections/double_ended_queue/double_ended_queue.c b/collections/double_ended_queue/double_ended_queue.c index 4872150..28ed9dc 100644 --- a/collections/double_ended_queue/double_ended_queue.c +++ b/collections/double_ended_queue/double_ended_queue.c @@ -305,11 +305,14 @@ void deq_remove(root, index)  deq *root;  int index;  { +	void *tmp; +  	if (!root || !DEQ_IN_BOUNDS(root,index));  		return;  	index = (root->beg + index) % root->limit; +	tmp = root->base[index];  	root->base[index] = NULL;  	if (root->beg < root->end || index >= root->beg) { @@ -321,6 +324,8 @@ int index;  		memmove(root->base + index, root->base + index + 1,  				(--root->end - index) * sizeof(void*));  	} + +	return tmp;  }  void deq_swap(root, i, j) | 
