Bug 25294 - All WebKit/win classes should return COMPtrs from their static constructor members
Summary: All WebKit/win classes should return COMPtrs from their static constructor me...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Windows XP
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar, PlatformOnly
Depends on:
Blocks:
 
Reported: 2009-04-20 07:42 PDT by Adam Roben (:aroben)
Modified: 2010-06-10 19:31 PDT (History)
2 users (show)

See Also:


Attachments
patch for MemoryStream (8.04 KB, patch)
2009-04-20 08:05 PDT, Adam Roben (:aroben)
no flags Details | Formatted Diff | Diff
Make CFDictionaryPropertyBag::createInstance return a COMPtr (17.85 KB, patch)
2009-11-05 10:09 PST, Adam Roben (:aroben)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Roben (:aroben) 2009-04-20 07:42:57 PDT
All classes in WebKit/win should return COMPtrs from their static constructor members (e.g., createInstance()). This will help prevent memory leaks/crashes caused by incorrect ref-count management.
Comment 1 Adam Roben (:aroben) 2009-04-20 07:43:11 PDT
<rdar://problem/6803127>
Comment 2 Adam Roben (:aroben) 2009-04-20 08:05:57 PDT
Created attachment 29616 [details]
patch for MemoryStream
Comment 3 Darin Adler 2009-04-20 09:19:39 PDT
Comment on attachment 29616 [details]
patch for MemoryStream

>  HRESULT STDMETHODCALLTYPE MemoryStream::Clone( 
>      /* [out] */ IStream** ppstm)
>  {
> -    *ppstm = MemoryStream::createInstance(m_buffer);
> +    *ppstm = MemoryStream::createInstance(m_buffer).releaseRef();
> +    // FIXME: MSDN says we should be returning STG_E_INSUFFICIENT_MEMORY instead of E_OUTOFMEMORY here.
>      return (*ppstm) ? S_OK : E_OUTOFMEMORY;

Why not copyRefTo here?

> -    COMPtr<IStream> stream(AdoptCOM, MemoryStream::createInstance(buffer.release()));
> +    COMPtr<MemoryStream> stream = MemoryStream::createInstance(buffer.release());
>      m_view->didReceiveData(stream.get());

Would this read better without the local variable?

> -    COMPtr<MemoryStream> result(AdoptCOM, MemoryStream::createInstance(SharedBuffer::wrapCFData(historyData.get())));
> +    COMPtr<MemoryStream> result = MemoryStream::createInstance(SharedBuffer::wrapCFData(historyData.get()));
>      return result.copyRefTo(stream);

Would this read better without the local variable?

r=me
Comment 4 Adam Roben (:aroben) 2009-04-20 09:23:24 PDT
(In reply to comment #3)
> (From update of attachment 29616 [details] [review])
> >  HRESULT STDMETHODCALLTYPE MemoryStream::Clone( 
> >      /* [out] */ IStream** ppstm)
> >  {
> > -    *ppstm = MemoryStream::createInstance(m_buffer);
> > +    *ppstm = MemoryStream::createInstance(m_buffer).releaseRef();
> > +    // FIXME: MSDN says we should be returning STG_E_INSUFFICIENT_MEMORY instead of E_OUTOFMEMORY here.
> >      return (*ppstm) ? S_OK : E_OUTOFMEMORY;
> 
> Why not copyRefTo here?

I originally thought that copyRefTo's behavior was incompatible with the existing behavior of this function. But now I see that it isn't. I will change to use copyRefTo.

> > -    COMPtr<IStream> stream(AdoptCOM, MemoryStream::createInstance(buffer.release()));
> > +    COMPtr<MemoryStream> stream = MemoryStream::createInstance(buffer.release());
> >      m_view->didReceiveData(stream.get());
> 
> Would this read better without the local variable?

Probably. I'll remove the variable.

> > -    COMPtr<MemoryStream> result(AdoptCOM, MemoryStream::createInstance(SharedBuffer::wrapCFData(historyData.get())));
> > +    COMPtr<MemoryStream> result = MemoryStream::createInstance(SharedBuffer::wrapCFData(historyData.get()));
> >      return result.copyRefTo(stream);
> 
> Would this read better without the local variable?

Maybe. I'll remove the variable and see how it looks.

Thanks for the review!
Comment 5 Adam Roben (:aroben) 2009-04-20 20:43:09 PDT
Comment on attachment 29616 [details]
patch for MemoryStream

Landed as r42692
Comment 6 Adam Roben (:aroben) 2009-11-05 10:09:46 PST
Created attachment 42574 [details]
Make CFDictionaryPropertyBag::createInstance return a COMPtr
Comment 7 Adam Roben (:aroben) 2009-11-05 10:17:48 PST
Comment on attachment 42574 [details]
Make CFDictionaryPropertyBag::createInstance return a COMPtr

Landed as r50567 <http://trac.webkit.org/changeset/50567>