From cc720fe821de52c5691c59b8fe21fd0793155a91 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 20 Jul 2019 12:38:40 +0200 Subject: [PATCH] win32: clear file dialog string before triggering callback Things would go weird if a plugin opens a new file dialog in the file callback, prevent this by clearing the string before the callback. --- dgl/src/Window.cpp | 5 +++-- distrho/extra/String.hpp | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index b5dc1715..09c47ac4 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -780,8 +780,9 @@ struct Window::PrivateData { #if defined(DISTRHO_OS_WINDOWS) && !defined(DGL_FILE_BROWSER_DISABLED) if (fSelectedFile.isNotEmpty()) { - fView->fileSelectedFunc(fView, fSelectedFile.buffer()); - fSelectedFile.clear(); + char* const buffer = fSelectedFile.getAndReleaseBuffer(); + fView->fileSelectedFunc(fView, buffer); + std::free(buffer); } #endif diff --git a/distrho/extra/String.hpp b/distrho/extra/String.hpp index 650c5bbd..5e258402 100644 --- a/distrho/extra/String.hpp +++ b/distrho/extra/String.hpp @@ -568,6 +568,18 @@ public: return fBuffer; } + /* + * Get and release the string buffer, while also clearing this string. + * Result must be freed. + */ + char* getAndReleaseBuffer() noexcept + { + char* const ret = fBuffer; + fBuffer = _null(); + fBufferLen = 0; + return ret; + } + // ------------------------------------------------------------------- // base64 stuff, based on http://www.adp-gmbh.ch/cpp/common/base64.html // Copyright (C) 2004-2008 René Nyffenegger