diff options
author | Simon Howard | 2006-02-23 23:41:13 +0000 |
---|---|---|
committer | Simon Howard | 2006-02-23 23:41:13 +0000 |
commit | 3d04d0264f490823896a37071300f8e2d2526a1b (patch) | |
tree | dcb94fccc77e34536a1dcc9ed1f9b02eaa6e43c1 | |
parent | ab6ecc6404515d6c400b6dc4c3a185df5aca8344 (diff) | |
download | chocolate-doom-3d04d0264f490823896a37071300f8e2d2526a1b.tar.gz chocolate-doom-3d04d0264f490823896a37071300f8e2d2526a1b.tar.bz2 chocolate-doom-3d04d0264f490823896a37071300f8e2d2526a1b.zip |
Track memory used by packet data to help detect memory leaks
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 385
-rw-r--r-- | src/net_packet.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/net_packet.c b/src/net_packet.c index 14623b4e..611a6ea6 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_packet.c 287 2006-01-13 02:20:12Z fraggle $ +// $Id: net_packet.c 385 2006-02-23 23:41:13Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.4 2006/02/23 23:41:13 fraggle +// Track memory used by packet data to help detect memory leaks +// // Revision 1.3 2006/01/13 02:20:12 fraggle // Signed integer read functions. Use these when reading ticcmd diffs. // @@ -40,6 +43,8 @@ #include "net_packet.h" #include "z_zone.h" +static int total_packet_memory = 0; + net_packet_t *NET_NewPacket(int initial_size) { net_packet_t *packet; @@ -54,6 +59,11 @@ net_packet_t *NET_NewPacket(int initial_size) packet->len = 0; packet->pos = 0; + total_packet_memory += sizeof(net_packet_t) + initial_size; + + //printf("total packet memory: %i bytes\n", total_packet_memory); + //printf("%p: allocated\n", packet); + return packet; } @@ -72,6 +82,9 @@ net_packet_t *NET_PacketDup(net_packet_t *packet) void NET_FreePacket(net_packet_t *packet) { + //printf("%p: destroyed\n", packet); + + total_packet_memory -= sizeof(net_packet_t) + packet->alloced; Z_Free(packet->data); Z_Free(packet); } @@ -217,6 +230,8 @@ char *NET_ReadString(net_packet_t *packet) static void NET_IncreasePacket(net_packet_t *packet) { byte *newdata; + + total_packet_memory -= packet->alloced; packet->alloced *= 2; @@ -226,6 +241,8 @@ static void NET_IncreasePacket(net_packet_t *packet) Z_Free(packet->data); packet->data = newdata; + + total_packet_memory += packet->alloced; } // Write a single byte to the packet |