Nothing like reading a reference code and seeing a memory leak.

Follow

Ok, it is not a memory leak. What the application have is something like

some_struct_t *data = malloc(sizeof(*data));

... which I believe what's happening is that it is getting the size of the struct by dereferencing the variable that will receive the allocation result.

In which case... WHAT THE FUCK, C?

the dereference is only apparent. sizeof doesn't execute its operand, only the type of the expression matters, and types and sizes are static in C, so it's all right. the most debatable point IMHO is that the variable is already in scope before it's initialized, but that's quite useful to initialize e.g. circular list, or one member pointing to another, so... it's all right, really. there's room for shooting your own feet, but C has never even tried to prevent that if that's what you wish to do, or even if it isn't ;-)
Sign in to participate in the conversation
Functional Café

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!