librt: Fix aliasing related segfault with vec append (#21303)
If there is another reference to the vec buffer that is grown during
append, the other buffer could see NULL pointers and trigger a segfault.
Now we only clear the buffer if there are no other references.