allocate using size of structure instead of size of pointer (fix for #19, probably for #23 and maybe #22)