You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Semi-related to #844, only this time on the client side. :) In network_data.cpp : NetworkSend_Command, a CommandPacket is malloc'd for use in the server's local cmd queue. However if it's the client, the CommandPacket* is allowed to go out of scope without being free'd.
So every time a client sends a cmd to the server, he leaks a little over 100 bytes of memory.
The quick fix is easy, just free it. A possibly better solution is to not put the CommandPacket on the heap to begin with. The attached patch eliminates the malloc unless it's truly needed.
I see the problem and the reason why the malloc isn't needed, but:
- there is absolutely no reason to make the command packet static (in global memory), allocation on the stack is good enough
- the logic of the function (even the whole network protocol) changes due to your changes that "look like" an optimization, but are not; clients get the callback too which they shouldn't get.
Yeah, using static was overkill, sorry about that. :)
I could have sworn I had set c.callback back to 0 before sending to clients. Wasn't trying to optimize so much as reorganize the function and make it more readable.
I noticed a fix isn't in trunk yet... in case it would be useful, a better patch (using stack and no logic changes) is attached. Thanks, and I'll continue to keep an eye out.
benc opened the ticket and wrote:
Attachments
Reported version: 0.5.2
Operating system: All
This issue was imported from FlySpray: https://bugs.openttd.org/task/846
The text was updated successfully, but these errors were encountered: