Module: kamailio Branch: 4.3 Commit: 2070b215872ce8d15375e9ccda8bb45b496ad44a URL: https://github.com/kamailio/kamailio/commit/2070b215872ce8d15375e9ccda8bb45b496ad44a
Author: Daniel-Constantin Mierla <[email protected]> Committer: Daniel-Constantin Mierla <[email protected]> Date: 2015-09-22T13:47:30+02:00 mem: f_malloc - proper inserting of last free large fragment - reported by Juha Heinanen (cherry picked from commit b58a55da1a43f1b2d3b1f0b831fcb639c57a66b9) --- Modified: mem/f_malloc.c --- Diff: https://github.com/kamailio/kamailio/commit/2070b215872ce8d15375e9ccda8bb45b496ad44a.diff Patch: https://github.com/kamailio/kamailio/commit/2070b215872ce8d15375e9ccda8bb45b496ad44a.patch --- diff --git a/mem/f_malloc.c b/mem/f_malloc.c index 90fa9ca..77dbd76 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 */ _______________________________________________ sr-dev mailing list [email protected] http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
