That sounds similar to my idea of callocSlice but applied to realloc as well. Which absolutely is the solution here I think. Using malloc directly should be a red flag.