aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/heap.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-11 13:51:08 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-11 13:51:08 +0100
commit38bced7829e676d43264ab1162034a6c3ad3f91d (patch)
tree17b399a1bbf27392ea692264557354e827e62cbc /src/libutil/heap.c
parente332d676926f23417c1efccdca72470de6008a46 (diff)
downloadrspamd-38bced7829e676d43264ab1162034a6c3ad3f91d.tar.gz
rspamd-38bced7829e676d43264ab1162034a6c3ad3f91d.zip
[Fix] Add more guards for heap
Diffstat (limited to 'src/libutil/heap.c')
-rw-r--r--src/libutil/heap.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/libutil/heap.c b/src/libutil/heap.c
index 47c996732..6fc1d9783 100644
--- a/src/libutil/heap.c
+++ b/src/libutil/heap.c
@@ -123,10 +123,17 @@ rspamd_min_heap_pop (struct rspamd_min_heap *heap)
elt = g_ptr_array_index (heap->ar, 0);
last = g_ptr_array_index (heap->ar, heap->ar->len - 1);
- /* Now replace elt with the last element and sink it if needed */
- heap_swap (heap, elt, last);
- g_ptr_array_remove_index_fast (heap->ar, heap->ar->len - 1);
- rspamd_min_heap_sink (heap, last);
+
+ if (elt != last) {
+ /* Now replace elt with the last element and sink it if needed */
+ heap_swap (heap, elt, last);
+ g_ptr_array_remove_index_fast (heap->ar, heap->ar->len - 1);
+ rspamd_min_heap_sink (heap, last);
+ }
+ else {
+ g_ptr_array_remove_index_fast (heap->ar, heap->ar->len - 1);
+ }
+
return elt;
}