MFC of 263062:

Avoid segment fault when attempting to clean up cylinder group
buffer cache.

PR:             187221
Submitted by:   Petr Lampa <lampa@fit.vutbr.cz>
Obtained from:  Petr Lampa <lampa@fit.vutbr.cz>
MFC after:      1 week

MFC of 262488:

Arguments for malloc and calloc should be size_t, not int.
Use proper bounds check when trying to free cached memory.

Spotted by: Xin Li
Tested by:  Dmitry Sivachenko
MFC after:  2 weeks