diff options
author | eihrul <eihrul> | 2006-10-03 15:39:29 +0000 |
---|---|---|
committer | eihrul <eihrul> | 2006-10-03 15:39:29 +0000 |
commit | df636cc8f79fac3c665a9740c5803ee71f965d16 (patch) | |
tree | 9b560f452585ee7990455c1f288f22782ca886c2 /packet.c | |
parent | e310eade3b48d3112fe9dcf99548c8c7bf2895e8 (diff) | |
download | enet-df636cc8f79fac3c665a9740c5803ee71f965d16.tar.gz enet-df636cc8f79fac3c665a9740c5803ee71f965d16.zip |
*** empty log message ***
Diffstat (limited to 'packet.c')
-rw-r--r-- | packet.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -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); |