From d9461c185e08cc8833fdf7c109a6d6618f2da33f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 6 May 2013 23:18:30 +0200 Subject: [PATCH] Device/Descriptor: fix double free() bug in OpenOnPort() When the user cancels the operation, clean up. Fixes a regression by commit 7b530132. --- src/Device/Descriptor.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Device/Descriptor.cpp b/src/Device/Descriptor.cpp index 1e5353a9d..9698a057c 100644 --- a/src/Device/Descriptor.cpp +++ b/src/Device/Descriptor.cpp @@ -230,7 +230,16 @@ DeviceDescriptor::OpenOnPort(Port *_port, OperationEnvironment &env) port->StartRxThread(); EnableNMEA(env); - return !env.IsCancelled(); + + if (env.IsCancelled()) { + /* the caller is responsible for freeing the port on error */ + port = nullptr; + delete device; + device = nullptr; + return false; + } + + return true; } bool -- 2.11.4.GIT