From 71b75500495d5e11ba5fbe937e421b349d3d3059 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Tue, 11 Sep 2012 02:28:50 +0300 Subject: [PATCH] treat destroying NULL as no-op --- host.c | 3 +++ packet.c | 3 +++ unix.c | 3 ++- win32.c | 3 ++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/host.c b/host.c index ec8731d..33c808a 100644 --- a/host.c +++ b/host.c @@ -135,6 +135,9 @@ enet_host_destroy (ENetHost * host) { ENetPeer * currentPeer; + if (host == NULL) + return; + enet_socket_destroy (host -> socket); for (currentPeer = host -> peers; diff --git a/packet.c b/packet.c index fd59b14..3adb287 100644 --- a/packet.c +++ b/packet.c @@ -55,6 +55,9 @@ enet_packet_create (const void * data, size_t dataLength, enet_uint32 flags) void enet_packet_destroy (ENetPacket * packet) { + if (packet == NULL) + return; + if (packet -> freeCallback != NULL) (* packet -> freeCallback) (packet); if (! (packet -> flags & ENET_PACKET_FLAG_NO_ALLOCATE) && diff --git a/unix.c b/unix.c index a225b57..c421b7e 100644 --- a/unix.c +++ b/unix.c @@ -273,7 +273,8 @@ enet_socket_accept (ENetSocket socket, ENetAddress * address) void enet_socket_destroy (ENetSocket socket) { - close (socket); + if (socket != -1) + close (socket); } int diff --git a/win32.c b/win32.c index 0a213e7..708d306 100644 --- a/win32.c +++ b/win32.c @@ -220,7 +220,8 @@ enet_socket_accept (ENetSocket socket, ENetAddress * address) void enet_socket_destroy (ENetSocket socket) { - closesocket (socket); + if (socket != INVALID_SOCKET) + closesocket (socket); } int