fix IOBuf::reserve() when operating on a user-supplied buffer
Summary:
The IOBuf::reserveSlow() code assumed that external buffers were always
allocated with malloc. This would cause problems when if reserve() was
ever used on a buffer created with IOBuf::takeOwnership().
This changes the code to now check if a user-specified free function has
been supplied. If so, then it does not try to use realloc()/rallocm(),
and it now frees the old buffer using the specified free function rather
than free().
User-supplied buffers also have a separately allocated SharedInfo
object, which must be freed when we no longer need it.
Test Plan:
Added additional unit tests to check calling reserve() on IOBufs created
with IOBuf::takeOwnership().
Reviewed By: davejwatson@fb.com
FB internal diff:
D1072292