Results 1 to 5 of 5

Thread: Network related memory leaks

  1. #1
    Peasant
    Join Date
    Apr 2011
    Posts
    6

    Default Network related memory leaks

    Using Clanlib 2.2.12, I'm seeing memory leaks when a client connects to the server. I've removed all of the sending of events between the client and server, and connect and disconnect are not doing anything, except for adding and removing the connection to a std::vector on the server.

    I'm seeing memory leaks in CL_Event constructor (event.cpp line 49) and also in CL_System::aligned_alloc (system.cpp line 75). These memory leaks eventually shutdown the app due to exhausting memory.

    Any idea on the cause of these memory leaks? I hesitate to say it's something outside of my code, but it runs without memory leaks as long as the client doesn't connect. And, I've removed anything that could potentially generate networking events.

  2. #2
    Master Sorcerer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    Doing a find in files for CL_System::aligned_alloc reveals the following classes in ClanLib:

    1) CL_InterlockedVariable
    2) CL_PixelBuffer
    3) CL_JPEGLoader
    4) CL_PixelBicubicRenderer

    None of those are used by any networking code in ClanLib.

    CL_Event line 49 is the allocation of the shared pointer guarded CL_Event_Impl. It is highly unlikely that you have found a bug in the shared pointer implementation, so this leak is most likely produced by something holding a CL_Event member.

    The networking code does have several CL_Event members, i.e. read and write event in CL_TCPConnection. If you are adding them to a std::vector that you are not emptying, then that would be a memory gathering bug in your application. Or maybe I misunderstood the line about the vector?

    Either way, we have no known memory leaks currently, so we need a small simple test example that demonstrates a leak to be able to debug and fix it.

  3. #3
    Peasant
    Join Date
    Apr 2011
    Posts
    6

    Default

    Quote Originally Posted by Magnus Norddahl View Post
    Either way, we have no known memory leaks currently, so we need a small simple test example that demonstrates a leak to be able to debug and fix it.
    I modified the example server and client demos (Examples\Network\NetGame) to add in CRT allocation checking (Attached below). To get the memory dump, I've modified it to exit the exec function on a client disconnect. The server has to be running under the Visual Studio IDE or DebugView (http://technet.microsoft.com/en-us/s...rnals/bb896647) has to be running.

    I've also added this to the Clanlib source so I get a more detailed dump:

    Detected memory leaks!
    Dumping objects ->
    {1426} normal block at 0x003A6310, 8 bytes long.
    Data: <tl: > 74 6C 3A 00 00 00 00 00
    {1425} normal block at 0x003A6C20, 104 bytes long.
    Data: < 4l: > 01 00 00 00 34 6C 3A 00 00 00 00 00 00 00 00 00
    {1326} normal block at 0x003A7530, 8 bytes long.
    Data: <`b: > 60 62 3A 00 00 00 00 00
    {362} normal block at 0x003A7FD8, 84 bytes long.
    Data: < : ? > E8 7F 3A 00 0A 00 00 00 00 00 00 00 3F 00 00 00
    {314} normal block at 0x003A6E48, 53 bytes long.
    Data: <void (__thiscall> 76 6F 69 64 20 28 5F 5F 74 68 69 73 63 61 6C 6C
    {313} normal block at 0x003A6E00, 8 bytes long.
    Data: <Hn: \: > 48 6E 3A 00 B0 5C 3A 00
    {301} normal block at 0x003A7578, 8 bytes long.
    Data: <tb: > 74 62 3A 00 00 00 00 00
    ..\Sources\Core\System\system.cpp(75) : {299} normal block at 0x003A74E0, 15 bytes long.
    Data: < t: > E0 74 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    ..\Sources\Core\System\system.cpp(75) : {298} normal block at 0x003A7490, 15 bytes long.
    Data: < t: > 90 74 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    {297} normal block at 0x003A7428, 44 bytes long.
    Data: < s: t: t: . > A0 73 3A 00 98 74 3A 00 E8 74 3A 00 B4 06 2E 01
    ..\Sources\Core\System\event.cpp(49) : {296} normal block at 0x003A73E0, 8 bytes long.
    Data: <4 . > 34 18 2E 01 AC 00 00 00
    ..\Sources\Core\System\event.cpp(49) : {295} normal block at 0x003A73A0, 4 bytes long.
    Data: < s: > E0 73 3A 00
    ..\Sources\Core\System\system.cpp(75) : {294} normal block at 0x003A7350, 15 bytes long.
    Data: <Ps: > 50 73 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    ..\Sources\Core\System\system.cpp(75) : {293} normal block at 0x003A7300, 15 bytes long.
    Data: < s: > 00 73 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    {292} normal block at 0x003A7298, 44 bytes long.
    Data: < r: s: Xs: . > 10 72 3A 00 08 73 3A 00 58 73 3A 00 B4 06 2E 01
    ..\Sources\Core\System\event.cpp(49) : {291} normal block at 0x003A7250, 8 bytes long.
    Data: <4 . > 34 18 2E 01 A8 00 00 00
    ..\Sources\Core\System\event.cpp(49) : {290} normal block at 0x003A7210, 4 bytes long.
    Data: <Pr: > 50 72 3A 00
    ..\Sources\Core\System\system.cpp(75) : {289} normal block at 0x003A71C0, 15 bytes long.
    Data: < q: > C0 71 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    ..\Sources\Core\System\system.cpp(75) : {288} normal block at 0x003A7170, 15 bytes long.
    Data: <pq: > 70 71 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    {287} normal block at 0x003A7108, 44 bytes long.
    Data: < p: xq: q: / > C0 70 3A 00 78 71 3A 00 C8 71 3A 00 C4 07 2F 01
    ..\Sources\Core\System\thread.cpp(43) : {286} normal block at 0x003A70C0, 8 bytes long.
    Data: <` / > 60 19 2F 01 D4 00 00 00
    ..\Sources\Core\System\system.cpp(75) : {285} normal block at 0x003A7070, 15 bytes long.
    Data: <pp: > 70 70 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    ..\Sources\Core\System\system.cpp(75) : {284} normal block at 0x003A7020, 15 bytes long.
    Data: < p: > 20 70 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    {283} normal block at 0x003A6CF0, 44 bytes long.
    Data: <@o: (p: xp: 4. > 40 6F 3A 00 28 70 3A 00 78 70 3A 00 04 34 2E 01
    ..\Sources\Network\Socket\socket_name.cpp(52) : {282} normal block at 0x003A6F40, 160 bytes long.
    Data: <Po: ? > 50 6F 3A 00 00 00 00 00 00 00 00 00 3F 00 00 00
    ..\Sources\Network\NetGame\connection.cpp(37) : {246} normal block at 0x003A6228, 96 bytes long.
    Data: < g: 4 / f: l: > B8 67 3A 00 34 FE 2F 00 B0 66 3A 00 F0 6C 3A 00
    ..\Sources\Core\System\system.cpp(75) : {244} normal block at 0x003A6768, 15 bytes long.
    Data: <hg: > 68 67 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    ..\Sources\Core\System\system.cpp(75) : {243} normal block at 0x003A6718, 15 bytes long.
    Data: < g: > 18 67 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    {242} normal block at 0x003A66B0, 44 bytes long.
    Data: <hf: g: pg: , / > 68 66 3A 00 20 67 3A 00 70 67 3A 00 2C 0F 2F 01
    ..\Sources\Core\IOData\iodevice.cpp(44) : {241} normal block at 0x003A6668, 8 bytes long.
    Data: < c: > 01 CD CD CD A8 63 3A 00
    ..\Sources\Core\System\system.cpp(75) : {240} normal block at 0x003A6610, 15 bytes long.
    Data: < f: > 10 66 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    ..\Sources\Core\System\system.cpp(75) : {239} normal block at 0x003A65C0, 15 bytes long.
    Data: < e: > C0 65 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    {238} normal block at 0x003A6558, 44 bytes long.
    Data: < e: e: f: . > 18 65 3A 00 C8 65 3A 00 18 66 3A 00 B4 06 2E 01
    ..\Sources\Core\System\event.cpp(60) : {237} normal block at 0x003A6518, 4 bytes long.
    Data: <h[: > 68 5B 3A 00
    ..\Sources\Network\Socket\iodevice_provider_tcp_co nnection.cpp(208) : {236} normal block at 0x003A5B68, 12 bytes long.
    Data: < H. c: > 00 48 2E 01 AC 63 3A 00 02 00 00 00
    ..\Sources\Core\System\system.cpp(75) : {235} normal block at 0x003A64C8, 15 bytes long.
    Data: < d: > C8 64 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    ..\Sources\Core\System\system.cpp(75) : {234} normal block at 0x003A6478, 15 bytes long.
    Data: <xd: > 78 64 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    {233} normal block at 0x003A6410, 44 bytes long.
    Data: <h\: d: d: . > 68 5C 3A 00 80 64 3A 00 D0 64 3A 00 B4 06 2E 01
    ..\Sources\Core\System\event.cpp(60) : {232} normal block at 0x003A5C68, 4 bytes long.
    Data: < _: > 90 5F 3A 00
    ..\Sources\Network\Socket\iodevice_provider_tcp_co nnection.cpp(207) : {231} normal block at 0x003A5F90, 12 bytes long.
    Data: < H. c: > 00 48 2E 01 AC 63 3A 00 01 00 00 00
    ..\Sources\Core\System\system.cpp(75) : {230} normal block at 0x003A6938, 15 bytes long.
    Data: <8i: > 38 69 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    ..\Sources\Core\System\system.cpp(75) : {229} normal block at 0x003A68E8, 15 bytes long.
    Data: < h: > E8 68 3A 00 ED ED ED ED 01 00 00 00 CD CD CD
    {228} normal block at 0x003A6880, 44 bytes long.
    Data: <@h: h: @i: . > 40 68 3A 00 F0 68 3A 00 40 69 3A 00 B4 06 2E 01
    ..\Sources\Core\System\event.cpp(60) : {227} normal block at 0x003A6840, 4 bytes long.
    Data: < g: > F8 67 3A 00
    ..\Sources\Network\Socket\iodevice_provider_tcp_co nnection.cpp(206) : {226} normal block at 0x003A67F8, 12 bytes long.
    Data: < H. c: > 00 48 2E 01 AC 63 3A 00 00 00 00 00
    ..\Sources\Network\Socket\tcp_connection.cpp(55) : {210} normal block at 0x003A63A8, 44 bytes long.
    Data: < A. > E4 41 2E 01 A4 00 00 00 01 CD CD CD B4 00 00 00
    {195} normal block at 0x003A5A10, 44 bytes long.
    Data: <void (__thiscall> 76 6F 69 64 20 28 5F 5F 74 68 69 73 63 61 6C 6C
    {194} normal block at 0x003A5CB0, 8 bytes long.
    Data: < Z: > 10 5A 3A 00 00 00 00 00
    Object dump complete.
    Attached Files Attached Files

  4. #4
    Master Sorcerer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    I managed to locate and fix a memory leak in CL_NetGameConnection::~CL_NetGameConnection() where the 'impl' allocated in the constructor was never deleted in the destructor.

    I've committed a fix for this to the 2.2, 2.3 and 2.4 subversion repositories. As a bonus side effect the client and server is less likely to crash on shutdown.

  5. #5
    Peasant
    Join Date
    Apr 2011
    Posts
    6

    Default

    That fixed it on my end also. Thank you.

Similar Threads

  1. Mystery bug, related to physics and engine reset.
    By speeder in forum Novashell Game Creation System
    Replies: 2
    Last Post: 04-03-2010, 05:13 PM
  2. Adventure game related
    By Uhfgood in forum Novashell Game Creation System
    Replies: 4
    Last Post: 09-28-2009, 04:05 PM
  3. SoundBuffer related memory problem
    By ehd19777 in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 08-27-2008, 06:38 PM
  4. Replies: 7
    Last Post: 08-26-2008, 09:57 PM
  5. Memory Leaks
    By in forum Funeral Quest
    Replies: 9
    Last Post: 03-06-2007, 11:00 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •