From df636cc8f79fac3c665a9740c5803ee71f965d16 Mon Sep 17 00:00:00 2001 From: eihrul Date: Tue, 3 Oct 2006 15:39:29 +0000 Subject: *** empty log message *** --- packet.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'packet.c') diff --git a/packet.c b/packet.c index 77b5583..db6f2d4 100644 --- a/packet.c +++ b/packet.c @@ -21,11 +21,16 @@ enet_packet_create (const void * data, size_t dataLength, enet_uint32 flags) { ENetPacket * packet = (ENetPacket *) enet_malloc (sizeof (ENetPacket)); - if(flags & ENET_PACKET_FLAG_NO_ALLOCATE) + if (flags & ENET_PACKET_FLAG_NO_ALLOCATE) packet -> data = (enet_uint8 *) data; else { packet -> data = (enet_uint8 *) enet_malloc (dataLength); + if (packet -> data == NULL) + { + enet_free (packet); + return NULL; + }; if (data != NULL) memcpy (packet -> data, data, dataLength); @@ -34,6 +39,7 @@ enet_packet_create (const void * data, size_t dataLength, enet_uint32 flags) packet -> referenceCount = 0; packet -> flags = flags; packet -> dataLength = dataLength; + packet -> freeCallback = NULL; return packet; } @@ -44,7 +50,9 @@ enet_packet_create (const void * data, size_t dataLength, enet_uint32 flags) void enet_packet_destroy (ENetPacket * packet) { - if((packet -> flags & ENET_PACKET_FLAG_NO_ALLOCATE) == 0) + if (packet -> freeCallback != NULL) + (* packet -> freeCallback) (packet); + if (! (packet -> flags & ENET_PACKET_FLAG_NO_ALLOCATE)) enet_free (packet -> data); enet_free (packet); } @@ -68,6 +76,9 @@ enet_packet_resize (ENetPacket * packet, size_t dataLength) } newData = (enet_uint8 *) enet_malloc (dataLength); + if (newData == NULL) + return -1; + memcpy (newData, packet -> data, packet -> dataLength); enet_free (packet -> data); -- cgit v1.2.3