aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2017-08-28 15:27:41 +0200
committerStig Bjørlykke <stig@bjorlykke.org>2017-08-28 17:13:03 +0000
commit464679f80f60173589b6f3476abc1e6177d1a43f (patch)
treee2e51d8cbd674bee64c8c0383426e957287e9347
parent287221e8d9591bf252392ec34959e24c49fcd275 (diff)
extcap: Close control handles when done
Ensure the event handles are closed when done to avoid leakages. Also improved the control reader to use WaitForSingleObject(). Change-Id: I1679d9c09e247b28117ec05c3e1b0f3ba0e99674 Ping-Bug: 13833 Reviewed-on: https://code.wireshark.org/review/23263 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
-rw-r--r--extcap_spawn.c1
-rw-r--r--ui/qt/interface_toolbar_reader.cpp20
2 files changed, 9 insertions, 12 deletions
diff --git a/extcap_spawn.c b/extcap_spawn.c
index d88c3945d0..a4d5e0d9c0 100644
--- a/extcap_spawn.c
+++ b/extcap_spawn.c
@@ -379,6 +379,7 @@ extcap_wait_for_pipe(HANDLE * pipe_handles, int num_pipe_handles, HANDLE pid)
else
{
pipeinsts[idx].pendingIO = FALSE;
+ CloseHandle(pipeinsts[idx].ol.hEvent);
num_waiting_to_connect--;
}
}
diff --git a/ui/qt/interface_toolbar_reader.cpp b/ui/qt/interface_toolbar_reader.cpp
index 99b15a47b3..bc7abfd008 100644
--- a/ui/qt/interface_toolbar_reader.cpp
+++ b/ui/qt/interface_toolbar_reader.cpp
@@ -43,8 +43,9 @@ const int header_size = 6;
int InterfaceToolbarReader::async_pipe_read(void *data, int nbyte)
{
BOOL success;
- DWORD nof_bytes_read, last_err;
+ DWORD nof_bytes_read;
OVERLAPPED overlap;
+ int bytes_read = -1;
overlap.Pointer = 0;
overlap.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
@@ -59,17 +60,12 @@ int InterfaceToolbarReader::async_pipe_read(void *data, int nbyte)
if (success && nof_bytes_read != 0)
{
// The read operation completed successfully.
- return nof_bytes_read;
+ bytes_read = nof_bytes_read;
}
-
- last_err = GetLastError();
-
- if (!success && last_err == ERROR_IO_PENDING)
+ else if (!success && GetLastError() == ERROR_IO_PENDING)
{
// The operation is still pending, wait for a signal.
- DWORD wait = WaitForMultipleObjects(1, &overlap.hEvent, TRUE, INFINITE);
-
- if (wait - WAIT_OBJECT_0 == 0)
+ if (WaitForSingleObject(overlap.hEvent, INFINITE) == WAIT_OBJECT_0)
{
// The wait operation has completed.
success = GetOverlappedResult(control_in_, &overlap, &nof_bytes_read, FALSE);
@@ -77,13 +73,13 @@ int InterfaceToolbarReader::async_pipe_read(void *data, int nbyte)
if (success && nof_bytes_read != 0)
{
// The get result operation completed successfully.
- return nof_bytes_read;
+ bytes_read = nof_bytes_read;
}
}
}
- // The pipe is closed or an unknown error occured.
- return -1;
+ CloseHandle(overlap.hEvent);
+ return bytes_read;
}
#endif