Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/neutrinolabs/ulalaca-xrdp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGyuhwan Park <unstabler@unstabler.pl>2022-10-06 14:44:45 +0300
committerGyuhwan Park <unstabler@unstabler.pl>2022-10-06 14:48:16 +0300
commit83572bb84ead27ac3caa7cbcaa325fecaf6d0244 (patch)
tree0af08deec9da7ce40f3176e3e9eb2cbde0799aaf
parentf06a16646ebb8cbb3e949cf86fb54696daa92ed7 (diff)
hotfix(IPCConnection): fix std::bad_alloc: use memmove() instead of releasing std::unique_ptr
-rw-r--r--IPCConnection.cpp2
-rw-r--r--IPCConnection.hpp17
2 files changed, 11 insertions, 8 deletions
diff --git a/IPCConnection.cpp b/IPCConnection.cpp
index a4bcd40..d74cd44 100644
--- a/IPCConnection.cpp
+++ b/IPCConnection.cpp
@@ -137,7 +137,7 @@ void IPCConnection::workerLoop() {
readPos += retval;
if (readPos >= contentLength) {
- promise.set_value(std::move(readBuffer));
+ promise->set_value(std::move(readBuffer));
{
std::scoped_lock<std::mutex> scopedReadTasksLock(_readTasksLock);
_readTasks.pop();
diff --git a/IPCConnection.hpp b/IPCConnection.hpp
index 1338853..82ad068 100644
--- a/IPCConnection.hpp
+++ b/IPCConnection.hpp
@@ -50,17 +50,20 @@ public:
std::unique_ptr<T, MallocFreeDeleter> read(size_t size) {
assert(size != 0);
- auto promise = std::promise<std::unique_ptr<uint8_t>>();
+ auto promise = std::make_shared<std::promise<std::unique_ptr<uint8_t>>>();
{
std::scoped_lock<std::mutex> scopedReadTasksLock(_readTasksLock);
_readTasks.emplace(size, promise);
}
- auto pointer = promise.get_future().get();
-
- return std::move(std::unique_ptr<T, MallocFreeDeleter>(
- reinterpret_cast<T *>(pointer.release()),
+ auto source = promise->get_future().get();
+ auto destination = std::unique_ptr<T, MallocFreeDeleter>(
+ (T *) malloc(size),
free
- ));
+ );
+
+ std::memmove(destination.get(), source.get(), size);
+
+ return std::move(destination);
}
void write(const void *pointer, size_t size);
@@ -79,7 +82,7 @@ private:
std::mutex _readTasksLock;
std::queue<std::pair<size_t, std::unique_ptr<uint8_t, MallocFreeDeleter>>> _writeTasks;
- std::queue<std::pair<size_t, std::promise<std::unique_ptr<uint8_t>> &>> _readTasks;
+ std::queue<std::pair<size_t, std::shared_ptr<std::promise<std::unique_ptr<uint8_t>>> >> _readTasks;
};