I based the code on darray_push() which apparently has the same problem. Maybe you can accept the patch and then fix both?