Commit fb3d5385 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

SMA->trim() did not return the trimmed space to the pool causing

the SMA to run out of space eventually.
parent c6e1e88d
......@@ -153,6 +153,7 @@ sma_trim(struct storage *s, size_t size)
struct sma_sc *sma_sc;
struct sma *sma;
void *p;
size_t delta;
CHECK_OBJ_NOTNULL(s, STORAGE_MAGIC);
CAST_OBJ_NOTNULL(sma, s->priv, SMA_MAGIC);
......@@ -160,12 +161,16 @@ sma_trim(struct storage *s, size_t size)
assert(sma->sz == sma->s.space);
assert(size < sma->sz);
delta = sma->sz - size;
if (delta < 256)
return;
if ((p = realloc(sma->s.ptr, size)) != NULL) {
Lck_Lock(&sma_sc->sma_mtx);
sma_sc->stats->g_bytes -= (sma->sz - size);
sma_sc->stats->c_freed += sma->sz - size;
sma_sc->sma_alloc -= delta;
sma_sc->stats->g_bytes -= delta;
sma_sc->stats->c_freed += delta;
if (sma_sc->sma_max != SIZE_MAX)
sma_sc->stats->g_space += sma->sz - size;
sma_sc->stats->g_space += delta;
sma->sz = size;
Lck_Unlock(&sma_sc->sma_mtx);
sma->s.ptr = p;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment