diff --git a/Sming/Components/Network/src/Network/Http/Websocket/WebsocketConnection.cpp b/Sming/Components/Network/src/Network/Http/Websocket/WebsocketConnection.cpp index ec4d5253a2..a7fc9a6b7b 100644 --- a/Sming/Components/Network/src/Network/Http/Websocket/WebsocketConnection.cpp +++ b/Sming/Components/Network/src/Network/Http/Websocket/WebsocketConnection.cpp @@ -301,10 +301,10 @@ void WebsocketConnection::broadcast(const char* message, size_t length, ws_frame { char* copy = new char[length]; memcpy(copy, message, length); - std::shared_ptr data(copy, [](const char* ptr) { delete[] ptr; }); + std::shared_ptr data(copy); for(auto skt : websocketList) { - auto stream = new SharedMemoryStream(data, length); + auto stream = new SharedMemoryStream(data, length); skt->send(stream, type); } } diff --git a/Sming/Core/Data/Stream/SharedMemoryStream.h b/Sming/Core/Data/Stream/SharedMemoryStream.h index 6b44b55f35..28faa54c95 100644 --- a/Sming/Core/Data/Stream/SharedMemoryStream.h +++ b/Sming/Core/Data/Stream/SharedMemoryStream.h @@ -28,7 +28,7 @@ template class SharedMemoryStream : public IDataSourceStream * @param buffer * @param capacity Size of buffer in elements */ - SharedMemoryStream(std::shared_ptr(buffer), size_t size) : buffer(buffer), capacity(size * sizeof(T)) + SharedMemoryStream(std::shared_ptr(buffer), size_t size) : buffer(buffer), capacity(size * buffer[0]) { } diff --git a/tests/HostTests/modules/Stream.cpp b/tests/HostTests/modules/Stream.cpp index d360be6d1d..9639a29979 100644 --- a/tests/HostTests/modules/Stream.cpp +++ b/tests/HostTests/modules/Stream.cpp @@ -171,8 +171,8 @@ class StreamTest : public TestGroup { // STL may perform one-time memory allocation for mutexes, etc. - std::shared_ptr data(new char[18]); - SharedMemoryStream(data, 18); + std::shared_ptr data(new char[18]); + SharedMemoryStream stream(data, 18); } auto memStart = MallocCount::getCurrent(); @@ -182,13 +182,13 @@ class StreamTest : public TestGroup { char* message = new char[18]; memcpy(message, "Wonderful data...", 18); - std::shared_ptr data(message, [&message](const char* p) { delete[] p; }); + std::shared_ptr data(message, [&message](const char* p) { delete[] p; }); debug_d("RefCount: %d", data.use_count()); - Vector*> list; + Vector*> list; for(unsigned i = 0; i < 4; i++) { - list.addElement(new SharedMemoryStream(data, strlen(message))); + list.addElement(new SharedMemoryStream(data, strlen(message))); } for(unsigned i = 0; i < list.count(); i++) {