malloc(sizeof(struct mything *)).
Cut and paste error.
That little star after mything can be dangerous when your are trying to allocate a mything and not a pointer to a mything. It gets worse when mything has a child that you subsequently allocate and zero out.
By zeroing out the allocated child you zero out the parents pointer to the child because sizeof(struct mything*) is only 4 bytes on a 32 bit platform. so the child gets allocated at the next malloc allocation chunk, which is usually <= 16 bytes, after the 4 bytes. Zaaamooo, you’ve nulled the parent pointer to the child that you know you’ve allocated.
Gotta Love C’s memory model.
A million and one ways to shoot yourself in the foot.
