[sr-dev] git:master:b58a55da: mem: f_malloc - proper inserting of last free large fragment

Daniel-Constantin Mierla miconda at gmail.com
Mon Sep 21 17:02:31 CEST 2015


Module: kamailio
Branch: master
Commit: b58a55da1a43f1b2d3b1f0b831fcb639c57a66b9
URL: https://github.com/kamailio/kamailio/commit/b58a55da1a43f1b2d3b1f0b831fcb639c57a66b9

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2015-09-21T17:01:18+02:00

mem: f_malloc - proper inserting of last free large fragment

- reported by Juha Heinanen

---

Modified: mem/f_malloc.c

---

Diff:  https://github.com/kamailio/kamailio/commit/b58a55da1a43f1b2d3b1f0b831fcb639c57a66b9.diff
Patch: https://github.com/kamailio/kamailio/commit/b58a55da1a43f1b2d3b1f0b831fcb639c57a66b9.patch

---

diff --git a/mem/f_malloc.c b/mem/f_malloc.c
index b0376eb..2221d54 100644
--- a/mem/f_malloc.c
+++ b/mem/f_malloc.c
@@ -211,27 +211,42 @@ static inline void fm_insert_free(struct fm_block* qm, struct fm_frag* frag)
 {
 	struct fm_frag* f;
 	int hash;
+	int after;
 	
 	hash=GET_HASH(frag->size);
 	f=qm->free_hash[hash].first;
 	if (frag->size > F_MALLOC_OPTIMIZE){ /* because of '<=' in GET_HASH,
 											(different from 0.8.1[24] on
 											 purpose --andrei ) */
+		after = 0;
 		/* large fragments list -- add at a position ordered by size */
-		for(; f && f->u.nxt_free!=qm->last_frag; f=f->u.nxt_free){
+		for(; f; f=f->u.nxt_free){
 			if (frag->size <= f->size) break;
+			if(f->u.nxt_free==qm->last_frag) {
+				/*size greater than last frag in slot*/
+				after = 1;
+				break;
+			}
 		}
 	
-		/*insert frag before f*/
-		frag->u.nxt_free = f;
 		if(f) {
-			frag->prv_free=f->prv_free;
-			if(f->prv_free) f->prv_free->u.nxt_free = frag;
-			if(qm->free_hash[hash].first==f) qm->free_hash[hash].first = frag;
+			if(after) {
+				/*insert frag after f*/
+				frag->prv_free=f;
+				f->u.nxt_free=frag;
+				frag->u.nxt_free = qm->last_frag;
+			} else {
+				/*insert frag before f*/
+				frag->u.nxt_free = f;
+				frag->prv_free=f->prv_free;
+				if(f->prv_free) f->prv_free->u.nxt_free = frag;
+				if(qm->free_hash[hash].first==f) qm->free_hash[hash].first = frag;
+			}
 		} else {
 			/* to be only one in slot */
 			qm->free_hash[hash].first = frag;
 			frag->prv_free=0;
+			frag->u.nxt_free = qm->last_frag;
 		}
 	} else {
 		/* fixed fragment size list -- add first */




More information about the sr-dev mailing list