Changeset 183189 in webkit
- Timestamp:
- Apr 23, 2015 9:53:05 AM (9 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r183188 r183189 1 2015-04-23 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [UNIX] Do not allow copies of IPC::Attachment 4 https://bugs.webkit.org/show_bug.cgi?id=144096 5 6 Reviewed by Darin Adler. 7 8 It ensures that the file descriptor ownership is always correctly 9 transferred. This way we can remove the dispose() method to 10 explicitly close the file descriptor and always close it in the 11 Attachment destructor (unless explicitly transferred to 12 IPC::Connection or SharedMemory). It simplifies the code and 13 ensure we don't leak file descriptors. 14 15 * Platform/IPC/ArgumentDecoder.cpp: 16 (IPC::ArgumentDecoder::~ArgumentDecoder): Remove the code to 17 explicitly dispose attachments. 18 (IPC::ArgumentDecoder::removeAttachment): Use WTF::move(). 19 * Platform/IPC/ArgumentEncoder.cpp: 20 (IPC::ArgumentEncoder::~ArgumentEncoder): Remove the code to 21 explicitly dispose attachments. 22 (IPC::ArgumentEncoder::addAttachment): Use WTF::move(). 23 (IPC::ArgumentEncoder::releaseAttachments): Simplify by using WTF::move(). 24 * Platform/IPC/ArgumentEncoder.h: 25 * Platform/IPC/Attachment.cpp: 26 (IPC::Attachment::encode): Move a copy of the attachment, and 27 reset the file descriptor, since the ownership is passed to the encoder. 28 * Platform/IPC/Attachment.h: Make copy constructor and assignment 29 private to not allow public copies. The only copy allowed is done 30 by Attachment::encode(). Make m_fileDescriptor mutable so that we 31 can reset it in Attachment::encode() after passing the ownership 32 to the encoder. 33 * Platform/IPC/unix/AttachmentUnix.cpp: 34 (IPC::Attachment::~Attachment): Close the file descriptor if it 35 hasn't been released explicitly. 36 (IPC::Attachment::dispose): Deleted. 37 * Platform/IPC/unix/ConnectionUnix.cpp: 38 (IPC::Connection::processMessage): Do not use AttachmentResourceGuard. 39 (IPC::Connection::sendOutgoingMessage): Ditto. 40 (IPC::AttachmentResourceGuard::AttachmentResourceGuard): Deleted. 41 (IPC::AttachmentResourceGuard::~AttachmentResourceGuard): Deleted. 42 * Platform/unix/SharedMemoryUnix.cpp: 43 (WebKit::SharedMemory::Handle::~Handle): Do not call clear(). 44 (WebKit::SharedMemory::Handle::clear): Reset the attachment. 45 * UIProcess/WebInspectorProxy.cpp: 46 (WebKit::WebInspectorProxy::createInspectorPage): Use WTF::move(). 47 * WebProcess/Plugins/PluginProcessConnectionManager.cpp: 48 (WebKit::PluginProcessConnectionManager::getPluginProcessConnection): 49 Call releaseFileDescriptor() instead of fileDescritpro() since the 50 ownership is passed to the connection. 51 1 52 2015-04-23 Alexey Proskuryakov <ap@apple.com> 2 53 -
trunk/Source/WebKit2/Platform/IPC/ArgumentDecoder.cpp
r176762 r183189 48 48 ASSERT(m_buffer); 49 49 free(m_buffer); 50 #if !USE(UNIX_DOMAIN_SOCKETS)51 50 // FIXME: We need to dispose of the mach ports in cases of failure. 52 #else53 Vector<Attachment>::iterator end = m_attachments.end();54 for (Vector<Attachment>::iterator it = m_attachments.begin(); it != end; ++it)55 it->dispose();56 #endif57 51 } 58 52 … … 220 214 return false; 221 215 222 attachment = m_attachments.last(); 223 m_attachments.removeLast(); 216 attachment = m_attachments.takeLast(); 224 217 return true; 225 218 } -
trunk/Source/WebKit2/Platform/IPC/ArgumentEncoder.cpp
r179707 r183189 71 71 if (m_buffer != m_inlineBuffer) 72 72 freeBuffer(m_buffer, m_bufferCapacity); 73 74 #if !USE(UNIX_DOMAIN_SOCKETS)75 73 // FIXME: We need to dispose of the attachments in cases of failure. 76 #else77 for (size_t i = 0; i < m_attachments.size(); ++i)78 m_attachments[i].dispose();79 #endif80 74 } 81 75 … … 192 186 } 193 187 194 void ArgumentEncoder::addAttachment( const Attachment& attachment)188 void ArgumentEncoder::addAttachment(Attachment&& attachment) 195 189 { 196 m_attachments.append( attachment);190 m_attachments.append(WTF::move(attachment)); 197 191 } 198 192 199 193 Vector<Attachment> ArgumentEncoder::releaseAttachments() 200 194 { 201 Vector<Attachment> newList; 202 newList.swap(m_attachments); 203 return newList; 195 return WTF::move(m_attachments); 204 196 } 205 197 -
trunk/Source/WebKit2/Platform/IPC/ArgumentEncoder.h
r177543 r183189 66 66 size_t bufferSize() const { return m_bufferSize; } 67 67 68 void addAttachment( const Attachment&);68 void addAttachment(Attachment&&); 69 69 Vector<Attachment> releaseAttachments(); 70 70 void reserve(size_t); -
trunk/Source/WebKit2/Platform/IPC/Attachment.cpp
r161148 r183189 53 53 void Attachment::encode(ArgumentEncoder& encoder) const 54 54 { 55 encoder.addAttachment( *this);55 encoder.addAttachment(WTF::move(*const_cast<Attachment*>(this))); 56 56 } 57 57 -
trunk/Source/WebKit2/Platform/IPC/Attachment.h
r183176 r183189 56 56 Attachment(Attachment&&); 57 57 Attachment& operator=(Attachment&&); 58 Attachment(const Attachment&) = default;59 Attachment& operator=(Attachment&) = default;60 58 Attachment(int fileDescriptor, size_t); 61 59 Attachment(int fileDescriptor); 60 ~Attachment(); 62 61 #endif 63 62 … … 76 75 int releaseFileDescriptor() { int temp = m_fileDescriptor; m_fileDescriptor = -1; return temp; } 77 76 int fileDescriptor() const { return m_fileDescriptor; } 78 79 void dispose();80 77 #endif 81 78 -
trunk/Source/WebKit2/Platform/IPC/unix/AttachmentUnix.cpp
r183176 r183189 68 68 } 69 69 70 void Attachment::dispose()70 Attachment::~Attachment() 71 71 { 72 if (m_fileDescriptor == -1) 73 return; 74 75 closeWithRetry(m_fileDescriptor); 76 m_fileDescriptor = -1; 72 if (m_fileDescriptor != -1) 73 closeWithRetry(m_fileDescriptor); 77 74 } 78 75 -
trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp
r183176 r183189 156 156 } 157 157 158 template<class T, class iterator>159 class AttachmentResourceGuard {160 public:161 AttachmentResourceGuard(T& attachments)162 : m_attachments(attachments)163 {164 }165 ~AttachmentResourceGuard()166 {167 iterator end = m_attachments.end();168 for (iterator i = m_attachments.begin(); i != end; ++i)169 i->dispose();170 }171 private:172 T& m_attachments;173 };174 175 158 bool Connection::processMessage() 176 159 { … … 215 198 216 199 Vector<Attachment> attachments(attachmentCount); 217 AttachmentResourceGuard<Vector<Attachment>, Vector<Attachment>::iterator> attachementDisposer(attachments);218 200 RefPtr<WebKit::SharedMemory> oolMessageBody; 219 201 … … 424 406 425 407 Vector<Attachment> attachments = encoder->releaseAttachments(); 426 AttachmentResourceGuard<Vector<Attachment>, Vector<Attachment>::iterator> attachementDisposer(attachments);427 428 408 if (attachments.size() > (attachmentMaxAmount - 1)) { 429 409 ASSERT_NOT_REACHED(); -
trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp
r183184 r183189 53 53 SharedMemory::Handle::~Handle() 54 54 { 55 clear();56 55 } 57 56 58 57 void SharedMemory::Handle::clear() 59 58 { 60 m_attachment .dispose();59 m_attachment = IPC::Attachment(); 61 60 } 62 61 -
trunk/Source/WebKit2/UIProcess/WebInspectorProxy.cpp
r182447 r183189 487 487 488 488 m_underTest = underTest; 489 m_connectionIdentifier = connectionIdentifier;489 m_connectionIdentifier = WTF::move(connectionIdentifier); 490 490 491 491 m_inspectorPage->process().send(Messages::WebInspectorUI::EstablishConnection(m_connectionIdentifier, m_inspectedPage->pageID(), m_underTest), m_inspectorPage->pageID()); -
trunk/Source/WebKit2/WebProcess/Plugins/PluginProcessConnectionManager.cpp
r180054 r183189 77 77 #if OS(DARWIN) 78 78 IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.port()); 79 #elif USE(UNIX_DOMAIN_SOCKETS) 80 IPC::Connection::Identifier connectionIdentifier = encodedConnectionIdentifier.releaseFileDescriptor(); 81 #endif 79 82 if (IPC::Connection::identifierIsNull(connectionIdentifier)) 80 return 0; 81 #elif USE(UNIX_DOMAIN_SOCKETS) 82 IPC::Connection::Identifier connectionIdentifier = encodedConnectionIdentifier.fileDescriptor(); 83 if (connectionIdentifier == -1) 84 return 0; 85 #endif 83 return nullptr; 86 84 87 85 RefPtr<PluginProcessConnection> pluginProcessConnection = PluginProcessConnection::create(this, pluginProcessToken, connectionIdentifier, supportsAsynchronousInitialization);
Note: See TracChangeset
for help on using the changeset viewer.