Title: [168351] trunk/Source/WebCore
Revision
168351
Author
zandober...@gmail.com
Date
2014-05-05 23:19:50 -0700 (Mon, 05 May 2014)

Log Message

[Soup] Use std::unique_ptr<char[]> for the read buffer in SocketStreamHandle
https://bugs.webkit.org/show_bug.cgi?id=132559

Reviewed by Carlos Garcia Campos.

Manage the read buffer array through a std::unique_ptr<char[]> object.
This avoids handling with the raw pointer and also ensures that the memory
allocated with the new[] operator is deleted with the delete[] operator,
a problem exposed by the AddressSanitizer in WebSocket tests.

* platform/network/soup/SocketStreamHandle.h:
* platform/network/soup/SocketStreamHandleSoup.cpp:
(WebCore::SocketStreamHandle::SocketStreamHandle):
(WebCore::SocketStreamHandle::connected):
(WebCore::SocketStreamHandle::readBytes):
(WebCore::SocketStreamHandle::platformClose):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (168350 => 168351)


--- trunk/Source/WebCore/ChangeLog	2014-05-06 06:06:28 UTC (rev 168350)
+++ trunk/Source/WebCore/ChangeLog	2014-05-06 06:19:50 UTC (rev 168351)
@@ -1,3 +1,22 @@
+2014-05-05  Zan Dobersek  <zdober...@igalia.com>
+
+        [Soup] Use std::unique_ptr<char[]> for the read buffer in SocketStreamHandle
+        https://bugs.webkit.org/show_bug.cgi?id=132559
+
+        Reviewed by Carlos Garcia Campos.
+
+        Manage the read buffer array through a std::unique_ptr<char[]> object.
+        This avoids handling with the raw pointer and also ensures that the memory
+        allocated with the new[] operator is deleted with the delete[] operator,
+        a problem exposed by the AddressSanitizer in WebSocket tests.
+
+        * platform/network/soup/SocketStreamHandle.h:
+        * platform/network/soup/SocketStreamHandleSoup.cpp:
+        (WebCore::SocketStreamHandle::SocketStreamHandle):
+        (WebCore::SocketStreamHandle::connected):
+        (WebCore::SocketStreamHandle::readBytes):
+        (WebCore::SocketStreamHandle::platformClose):
+
 2014-05-05  Dirk Schulze  <k...@webkit.org>
 
         Adapt inline SVG sizing behavior to Firefox and Blink

Modified: trunk/Source/WebCore/platform/network/soup/SocketStreamHandle.h (168350 => 168351)


--- trunk/Source/WebCore/platform/network/soup/SocketStreamHandle.h	2014-05-06 06:06:28 UTC (rev 168350)
+++ trunk/Source/WebCore/platform/network/soup/SocketStreamHandle.h	2014-05-06 06:19:50 UTC (rev 168351)
@@ -67,7 +67,7 @@
         GRefPtr<GInputStream> m_inputStream;
         GRefPtr<GPollableOutputStream> m_outputStream;
         GRefPtr<GSource> m_writeReadySource;
-        char* m_readBuffer;
+        std::unique_ptr<char[]> m_readBuffer;
         void* m_id;
 
         SocketStreamHandle(const URL&, SocketStreamHandleClient*);

Modified: trunk/Source/WebCore/platform/network/soup/SocketStreamHandleSoup.cpp (168350 => 168351)


--- trunk/Source/WebCore/platform/network/soup/SocketStreamHandleSoup.cpp	2014-05-06 06:06:28 UTC (rev 168350)
+++ trunk/Source/WebCore/platform/network/soup/SocketStreamHandleSoup.cpp	2014-05-06 06:19:50 UTC (rev 168351)
@@ -84,7 +84,6 @@
 
 SocketStreamHandle::SocketStreamHandle(const URL& url, SocketStreamHandleClient* client)
     : SocketStreamHandleBase(url, client)
-    , m_readBuffer(0)
 {
     LOG(Network, "SocketStreamHandle %p new client %p", this, m_client);
     unsigned int port = url.hasPort() ? url.port() : (url.protocolIs("wss") ? 443 : 80);
@@ -99,7 +98,6 @@
 
 SocketStreamHandle::SocketStreamHandle(GSocketConnection* socketConnection, SocketStreamHandleClient* client)
     : SocketStreamHandleBase(URL(), client)
-    , m_readBuffer(0)
 {
     LOG(Network, "SocketStreamHandle %p new client %p", this, m_client);
     m_id = activateHandle(this);
@@ -125,8 +123,8 @@
     m_outputStream = G_POLLABLE_OUTPUT_STREAM(g_io_stream_get_output_stream(G_IO_STREAM(m_socketConnection.get())));
     m_inputStream = g_io_stream_get_input_stream(G_IO_STREAM(m_socketConnection.get()));
 
-    m_readBuffer = new char[READ_BUFFER_SIZE];
-    g_input_stream_read_async(m_inputStream.get(), m_readBuffer, READ_BUFFER_SIZE, G_PRIORITY_DEFAULT, 0,
+    m_readBuffer = std::make_unique<char[]>(READ_BUFFER_SIZE);
+    g_input_stream_read_async(m_inputStream.get(), m_readBuffer.get(), READ_BUFFER_SIZE, G_PRIORITY_DEFAULT, 0,
         reinterpret_cast<GAsyncReadyCallback>(readReadyCallback), m_id);
 
     m_state = Open;
@@ -147,9 +145,9 @@
 
     // The client can close the handle, potentially removing the last reference.
     RefPtr<SocketStreamHandle> protect(this); 
-    m_client->didReceiveSocketStreamData(this, m_readBuffer, bytesRead);
+    m_client->didReceiveSocketStreamData(this, m_readBuffer.get(), bytesRead);
     if (m_inputStream) // The client may have closed the connection.
-        g_input_stream_read_async(m_inputStream.get(), m_readBuffer, READ_BUFFER_SIZE, G_PRIORITY_DEFAULT, 0,
+        g_input_stream_read_async(m_inputStream.get(), m_readBuffer.get(), READ_BUFFER_SIZE, G_PRIORITY_DEFAULT, 0,
             reinterpret_cast<GAsyncReadyCallback>(readReadyCallback), m_id);
 }
 
@@ -205,8 +203,7 @@
 
     m_outputStream = 0;
     m_inputStream = 0;
-    delete m_readBuffer;
-    m_readBuffer = 0;
+    m_readBuffer = nullptr;
 
     m_client->didCloseSocketStream(this);
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to