ufairiya / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

Possible memory leak on Win32 #54

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version of the product are you using? On what operating system?
Mongoose 2.6, Windows (all versions)

Please provide any additional information below.
Just reading through the new source code and noticed that WSACleanup() is
not called anywhere?

http://msdn.microsoft.com/en-us/library/ms741549(VS.85).aspx

Original issue reported on code.google.com by PKuo...@gmail.com on 3 Jun 2009 at 2:22

GoogleCodeExporter commented 9 years ago
I don't think this is a big problem, since:
1. Mongoose is a library, and if it is embedded in the app, it should not 
decide on
app's behalf to WSACleanup
2. this leak is not cumulative, it is one-off and can be neglected.

Original comment by valenok on 3 Jun 2009 at 11:08

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I think, then, you should consider removing the #if/#endif for the _WIN32 in 
the init
routine for not calling WSAStartup() on developer's behave. That way, one would
remember to call WSACleanup() since he/she called WSAStartup(), as part of good
housekeeping programming practices.

Otherwise, the "fix" is simply adding #if/#endif to mg_stop to call 
WSACleanup() at
the end, after freeing ctx.

Original comment by PKuo...@gmail.com on 4 Jun 2009 at 8:15

GoogleCodeExporter commented 9 years ago
What happens if application continues to run after mg_stop(), using sockets?

Original comment by valenok on 4 Jun 2009 at 8:56

GoogleCodeExporter commented 9 years ago
Nothing IF the developer made his/her own WSAStartup() call, like a "good 
Windows
programmer" should -- WSAStartup() may be called multiple times (after the first
call, it just keeps a counter on how many times it has been called). Then
WSACleanup() would check on this internal counter to see if an actual cleanup 
should
be performed or just decrease the counter - the cleanup happens on the last 
counter
value.

Therefore, for "proper" (Windows) development, one calls WSAStartup because 
he/she
will use sockets, then calls mg_start (which calls WSAStartup). mg_stop is 
called,
WSACleanup is called so that cancels out the "inner" WSAStartup, but the socket 
world
is still happen and alive. Then the developer is done with his/her socket usage 
and
calls WSACleanup, that matches the first WSAStartup so an actual cleanup takes 
place.

Happy ending for all. (I hope!)

Original comment by PKuo...@gmail.com on 4 Jun 2009 at 9:50

GoogleCodeExporter commented 9 years ago

Original comment by valenok on 4 Jun 2009 at 9:52

GoogleCodeExporter commented 9 years ago
Submitted http://code.google.com/p/mongoose/source/detail?r=436
Thank you.

Original comment by valenok on 5 Jul 2009 at 7:32