From: Mikko Rasa Date: Tue, 15 Oct 2013 12:45:59 +0000 (+0300) Subject: Avoid closing handles twice X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=commitdiff_plain;h=8e696b9c1ee35f2ce5b9264f31b1963758d65ced;ds=sidebyside Avoid closing handles twice --- diff --git a/source/io/unix/handle.cpp b/source/io/unix/handle.cpp index 9546df9..ea8fa4e 100644 --- a/source/io/unix/handle.cpp +++ b/source/io/unix/handle.cpp @@ -50,7 +50,11 @@ unsigned sys_write(Handle &handle, const char *buf, unsigned size) void sys_close(Handle &handle) { - close(*handle); + if(handle) + { + close(*handle); + *handle = INVALID_HANDLE_VALUE; + } } } // namespace IO diff --git a/source/io/windows/handle.cpp b/source/io/windows/handle.cpp index 5b1d933..17aabb0 100644 --- a/source/io/windows/handle.cpp +++ b/source/io/windows/handle.cpp @@ -35,7 +35,11 @@ unsigned sys_write(Handle &handle, const char *buf, unsigned size) void sys_close(Handle &handle) { - CloseHandle(*handle); + if(handle) + { + CloseHandle(*handle); + *handle = INVALID_HANDLE_VALUE; + } } } // namespace IO