Fix struct alloc

And add test case for it.