From 8df39c1ac66b8fe38f804e14459b831491ad6270 Mon Sep 17 00:00:00 2001
From: Thomas Habets <thomas@habets.se>
Date: Tue, 11 Aug 2020 12:09:21 +0100
Subject: blocks/tcp_connection: Remove manual memory management

---
 gr-blocks/lib/tcp_connection.cc | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

(limited to 'gr-blocks/lib/tcp_connection.cc')

diff --git a/gr-blocks/lib/tcp_connection.cc b/gr-blocks/lib/tcp_connection.cc
index 4634039ae4..e262ca01ac 100644
--- a/gr-blocks/lib/tcp_connection.cc
+++ b/gr-blocks/lib/tcp_connection.cc
@@ -45,10 +45,10 @@ void tcp_connection::send(pmt::pmt_t vector)
     size_t len = pmt::blob_length(vector);
 
     // Asio async_write() requires the buffer to remain valid until the handler is called.
-    std::shared_ptr<char[]> txbuf(new char[len]);
+    auto txbuf = std::make_shared<std::vector<char>>(len);
 
     size_t temp = 0;
-    memcpy(txbuf.get(), pmt::uniform_vector_elements(vector, temp), len);
+    memcpy(txbuf->data(), pmt::uniform_vector_elements(vector, temp), len);
 
     size_t offset = 0;
     while (offset < len) {
@@ -58,12 +58,8 @@ void tcp_connection::send(pmt::pmt_t vector)
         size_t send_len = std::min((len - offset), d_buf.size());
         boost::asio::async_write(
             d_socket,
-            boost::asio::buffer(txbuf.get() + offset, send_len),
-            boost::bind(&tcp_connection::handle_write,
-                        this,
-                        txbuf,
-                        boost::asio::placeholders::error,
-                        boost::asio::placeholders::bytes_transferred));
+            boost::asio::buffer(txbuf->data() + offset, send_len),
+            [txbuf](const boost::system::error_code& error, size_t bytes_transferred) {});
         offset += send_len;
     }
 }
-- 
cgit v1.2.3