Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug#245678: zsh: built-in rm -rf fills up the memory



On May 9,  7:30pm, Clint Adams wrote:
}
} > And you're saying that (h->used + (new - old) <= HEAP_ARENA_SIZE) is 
} > always false, so the zhalloc() is always called?
} 
} I don't know that it's always false, but here's a small snapshot of
} those comparisons during a zsh/files rm -rf attempt.
} 
} [ h->used + (new - old) > HEAP_ARENA_SIZE ]
} 63432 + (63504 - 63432) > 16360

Aha!  Note that h->used > HEAP_ARENA_SIZE all by itself!

Comparing to HEAP_ARENA_SIZE is likely wrong, it should compare to the 
maximum of either HEAP_ARENA_SIZE or the previously-mmapped page size.
I'm not entirely sure of that ...

... but that's why it begins re-zhalloc()-ing.  In the non-MMAP case it
falls back on realloc() when a single allocation exceeds HEAP_ARENA_SIZE.

So what probably needs to happen to prevent the out-of-memory condition
is that we need to explicitly munmap the old mmap'd block, somewhere.

And then we need to emulate realloc() behavior somehow, in terms of
knowing whether to actually re-mmap-and-copy or whether the existing
mapped pages are large enough to contain the additional requested space.



Messages sorted by: Reverse Date, Date, Thread, Author