Bug 1221547 - part 1 - enable UnixSocketRawData to take ownership of a passed-in-buffer; r=tzimmerman
authorNathan Froyd <froydnj@mozilla.com>
Mon, 02 Nov 2015 16:13:10 -0500
changeset 308656 309cf6675d4e3b36f7b6dac968cdcede47616294
parent 308655 89f3fe7202921aaf81b78cc1287b5e99940dc85b
child 308657 756632e20aa46ce0b2feebdf6f04e6dacdc09811
push id7513
push useratolfsen@mozilla.com
push dateFri, 13 Nov 2015 14:03:43 +0000
reviewerstzimmerman
bugs1221547
milestone45.0a1
Bug 1221547 - part 1 - enable UnixSocketRawData to take ownership of a passed-in-buffer; r=tzimmerman
ipc/unixsocket/SocketBase.cpp
ipc/unixsocket/SocketBase.h
--- a/ipc/unixsocket/SocketBase.cpp
+++ b/ipc/unixsocket/SocketBase.cpp
@@ -120,16 +120,25 @@ UnixSocketRawData::UnixSocketRawData(con
   MOZ_ASSERT(aData || !aSize);
 
   MOZ_COUNT_CTOR_INHERITED(UnixSocketRawData, UnixSocketIOBuffer);
 
   ResetBuffer(static_cast<uint8_t*>(memcpy(new uint8_t[aSize], aData, aSize)),
               0, aSize, aSize);
 }
 
+UnixSocketRawData::UnixSocketRawData(UniquePtr<uint8_t[]> aData, size_t aSize)
+{
+  MOZ_ASSERT(aData || !aSize);
+
+  MOZ_COUNT_CTOR_INHERITED(UnixSocketRawData, UnixSocketIOBuffer);
+
+  ResetBuffer(aData.release(), 0, aSize, aSize);
+}
+
 UnixSocketRawData::UnixSocketRawData(size_t aSize)
 {
   MOZ_COUNT_CTOR_INHERITED(UnixSocketRawData, UnixSocketIOBuffer);
 
   ResetBuffer(new uint8_t[aSize], 0, 0, aSize);
 }
 
 UnixSocketRawData::~UnixSocketRawData()
--- a/ipc/unixsocket/SocketBase.h
+++ b/ipc/unixsocket/SocketBase.h
@@ -6,16 +6,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
 #ifndef mozilla_ipc_SocketBase_h
 #define mozilla_ipc_SocketBase_h
 
 #include "base/message_loop.h"
 #include "nsAutoPtr.h"
+#include "mozilla/UniquePtr.h"
 
 namespace mozilla {
 namespace ipc {
 
 //
 // UnixSocketBuffer
 //
 
@@ -226,16 +227,25 @@ public:
    * new instance of |UnixSocketRawData|.
    *
    * @param aData The buffer to copy.
    * @param aSize The number of bytes in |aData|.
    */
   UnixSocketRawData(const void* aData, size_t aSize);
 
   /**
+   * This constructor takes ownership of the data in aData.  The
+   * data is assumed to be aSize bytes in length.
+   *
+   * @param aData The buffer to take ownership of.
+   * @param aSize The number of bytes in |aData|.
+   */
+  UnixSocketRawData(UniquePtr<uint8_t[]> aData, size_t aSize);
+
+  /**
    * This constructor reserves aSize bytes of space. Currently
    * it's only possible to fill this buffer by calling |Receive|.
    *
    * @param aSize The number of bytes to allocate.
    */
   UnixSocketRawData(size_t aSize);
 
   /**