diff options
author | Jason Evans <je@fb.com> | 2012-04-24 05:07:30 (GMT) |
---|---|---|
committer | Jason Evans <je@fb.com> | 2012-04-24 05:07:30 (GMT) |
commit | 7e060397a38e301d7d3317fbf138f342c2bbd1b9 (patch) | |
tree | 633d6a94e309fa104ccc22a64d4f900ea425a4f4 | |
parent | 9cd351d147d1e79bff6b89586f168e81c0be034e (diff) | |
download | jemalloc-7e060397a38e301d7d3317fbf138f342c2bbd1b9.zip jemalloc-7e060397a38e301d7d3317fbf138f342c2bbd1b9.tar.gz jemalloc-7e060397a38e301d7d3317fbf138f342c2bbd1b9.tar.bz2 |
Fix quarantine_grow() bugs.
-rw-r--r-- | src/quarantine.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/quarantine.c b/src/quarantine.c index 88d0c77..9005ab3 100644 --- a/src/quarantine.c +++ b/src/quarantine.c @@ -72,23 +72,22 @@ quarantine_grow(quarantine_t *quarantine) return (quarantine); ret->curbytes = quarantine->curbytes; - if (quarantine->first + quarantine->curobjs < (ZU(1) << + ret->curobjs = quarantine->curobjs; + if (quarantine->first + quarantine->curobjs <= (ZU(1) << quarantine->lg_maxobjs)) { /* objs ring buffer data are contiguous. */ memcpy(ret->objs, &quarantine->objs[quarantine->first], quarantine->curobjs * sizeof(quarantine_obj_t)); - ret->curobjs = quarantine->curobjs; } else { /* objs ring buffer data wrap around. */ - size_t ncopy = (ZU(1) << quarantine->lg_maxobjs) - + size_t ncopy_a = (ZU(1) << quarantine->lg_maxobjs) - quarantine->first; - memcpy(ret->objs, &quarantine->objs[quarantine->first], ncopy * + size_t ncopy_b = quarantine->curobjs - ncopy_a; + + memcpy(ret->objs, &quarantine->objs[quarantine->first], ncopy_a + * sizeof(quarantine_obj_t)); + memcpy(&ret->objs[ncopy_a], quarantine->objs, ncopy_b * sizeof(quarantine_obj_t)); - ret->curobjs = ncopy; - if (quarantine->curobjs != 0) { - memcpy(&ret->objs[ret->curobjs], quarantine->objs, - quarantine->curobjs - ncopy); - } } return (ret); |