From fc2ce885767b932eb60ac67df506fd2e51611fe5 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 30 Jun 2015 15:27:44 +0100 Subject: [PATCH] Prevented accidental opening of already-open named pipes on win32. --- modules/juce_core/native/juce_win32_Files.cpp | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/modules/juce_core/native/juce_win32_Files.cpp b/modules/juce_core/native/juce_win32_Files.cpp index b4bbd9b83b..c51a370f0e 100644 --- a/modules/juce_core/native/juce_win32_Files.cpp +++ b/modules/juce_core/native/juce_win32_Files.cpp @@ -795,18 +795,19 @@ public: connected (false), ownsPipe (createPipe), shouldStop (false) { if (createPipe) + { pipeH = CreateNamedPipe (filename.toWideCharPointer(), PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0, PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, 0); + + if (GetLastError() == ERROR_ALREADY_EXISTS) + closePipeHandle(); + } } ~Pimpl() { - disconnectPipe(); - - if (pipeH != INVALID_HANDLE_VALUE) - CloseHandle (pipeH); - + closePipeHandle(); CloseHandle (cancelEvent); } @@ -868,6 +869,16 @@ public: } } + void closePipeHandle() + { + if (pipeH != INVALID_HANDLE_VALUE) + { + disconnectPipe(); + CloseHandle (pipeH); + pipeH = INVALID_HANDLE_VALUE; + } + } + int read (void* destBuffer, const int maxBytesToRead, const int timeOutMilliseconds) { while (connect (timeOutMilliseconds))