ts_stdlib: optimal buffer sizing works properly, no more valgrind warnings!