It looks correct, but you can throw away those stacked &* since that just dereferences the pointer then takes its address (effectively doing nothing). You can also just free(orig_ptr) at the end instead of assigning it to a different variable first.