Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/socket/packet.cc

Issue 443693002: [NaCl SDK] nacl_io: Remove use of new/delete for data buffers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "nacl_io/socket/packet.h" 5 #include "nacl_io/socket/packet.h"
6 6
7 #include <assert.h>
7 #include <string.h> 8 #include <string.h>
8 9
9 #include "nacl_io/pepper_interface.h" 10 #include "nacl_io/pepper_interface.h"
10 11
11 namespace nacl_io { 12 namespace nacl_io {
12 13
13 Packet::Packet(PepperInterface* ppapi) 14 Packet::Packet(PepperInterface* ppapi)
14 : ppapi_(ppapi), addr_(0), buffer_(NULL), len_(0) { 15 : ppapi_(ppapi), addr_(0), buffer_(NULL), len_(0) {
15 } 16 }
16 17
17 Packet::~Packet() { 18 Packet::~Packet() {
18 if ((NULL != ppapi_) && addr_) 19 if ((NULL != ppapi_) && addr_)
19 ppapi_->ReleaseResource(addr_); 20 ppapi_->ReleaseResource(addr_);
20 delete[] buffer_; 21 free(buffer_);
21 }
22
23 void Packet::Take(const void* buffer, size_t len, PP_Resource addr) {
24 addr_ = addr;
25 len_ = len;
26 buffer_ = static_cast<char*>(const_cast<void*>(buffer));
27 } 22 }
28 23
29 void Packet::Copy(const void* buffer, size_t len, PP_Resource addr) { 24 void Packet::Copy(const void* buffer, size_t len, PP_Resource addr) {
30 addr_ = addr; 25 addr_ = addr;
31 len_ = len; 26 len_ = len;
32 buffer_ = new char[len]; 27 buffer_ = (char*)malloc(len);
28 assert(buffer_);
33 29
34 memcpy(buffer_, buffer, len); 30 memcpy(buffer_, buffer, len);
35 if (addr && (NULL != ppapi_)) 31 if (addr && (NULL != ppapi_))
36 ppapi_->AddRefResource(addr); 32 ppapi_->AddRefResource(addr);
37 } 33 }
38 34
39 } // namespace nacl_io 35 } // namespace nacl_io
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/socket/packet.h ('k') | native_client_sdk/src/libraries/nacl_io/socket/tcp_node.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698