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

Issue 1074963003: Clean up potentially leaky use of base::DeletePointer. (Closed)

Created:
5 years, 8 months ago by hubbe
Modified:
5 years, 7 months ago
Reviewers:
danakj
CC:
chromium-reviews, qsr+mojo_chromium.org, zea+watch_chromium.org, viettrungluu+watch_chromium.org, posciak+watch_chromium.org, yzshen+watch_chromium.org, hguihot+watch_chromium.org, ben+mojo_chromium.org, miu+watch_chromium.org, tim+watch_chromium.org, mikhal+watch_chromium.org, jdduke+watch_chromium.org, jam, abarth-chromium, pvalenzuela+watch_chromium.org, darin-cc_chromium.org, erikwright+watch_chromium.org, hubbe+watch_chromium.org, mlamouri+watch-content_chromium.org, imcheng+watch_chromium.org, tdresser+watch_chromium.org, jasonroberts+watch_google.com, feature-media-reviews_chromium.org, maniscalco+watch_chromium.org, hclam+watch_chromium.org, maxbogue+watch_chromium.org, avayvod+watch_chromium.org, mcasas+watch_chromium.org, pwestin+watch_google.com, Aaron Boodman, plaree+watch_chromium.org, mkwst+moarreviews-renderer_chromium.org, darin (slow to review), wjia+watch_chromium.org, maniscalco
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Clean up potentially leaky use of base::DeletePointer. Posting a task to another thread doesn't guarantee that it will run, and we should make sure to clean things up when it doesn't. Most usage of base::DeletePointer seems to ignore this possibility, so I changed DeletePointer to require explicit ownership of the pointer.

Patch Set 1 #

Patch Set 2 : merged #

Patch Set 3 : merged #

Patch Set 4 : compile fixes #

Patch Set 5 : compile fix #

Patch Set 6 : compile fix 3 #

Patch Set 7 : compile fix 4 #

Patch Set 8 : owned() fix #

Patch Set 9 : fix stupid mistake #

Patch Set 10 : fixed another probleb #

Unified diffs Side-by-side diffs Delta from patch set Stats (+76 lines, -71 lines) Patch
M base/bind_helpers.h View 2 chunks +3 lines, -2 lines 0 comments Download
M chrome/browser/sync/profile_sync_service_typed_url_unittest.cc View 1 2 1 chunk +1 line, -1 line 0 comments Download
M chromeos/network/firewall_hole.cc View 1 2 3 4 1 chunk +3 lines, -1 line 0 comments Download
M components/history/core/browser/history_backend.cc View 1 2 1 chunk +1 line, -1 line 0 comments Download
M content/browser/media/capture/web_contents_audio_input_stream.cc View 1 chunk +1 line, -3 lines 0 comments Download
M content/browser/media/capture/web_contents_audio_input_stream_unittest.cc View 1 2 3 4 5 6 7 8 9 3 chunks +5 lines, -8 lines 0 comments Download
M content/renderer/media/webrtc/media_stream_remote_video_source.cc View 1 1 chunk +3 lines, -1 line 0 comments Download
M dbus/object_manager.h View 1 chunk +1 line, -1 line 0 comments Download
M dbus/object_manager.cc View 2 chunks +5 lines, -6 lines 0 comments Download
M dbus/object_proxy.h View 1 chunk +1 line, -1 line 0 comments Download
M dbus/object_proxy.cc View 4 chunks +7 lines, -9 lines 0 comments Download
M device/core/device_monitor_win.cc View 1 2 3 4 5 6 2 chunks +5 lines, -5 lines 0 comments Download
M device/hid/hid_service.h View 1 chunk +1 line, -1 line 0 comments Download
M device/hid/hid_service.cc View 1 2 2 chunks +4 lines, -2 lines 0 comments Download
M device/usb/usb_service.h View 1 2 1 chunk +0 lines, -2 lines 0 comments Download
M ipc/mojo/async_handle_waiter.cc View 1 2 3 4 5 6 7 3 chunks +11 lines, -3 lines 0 comments Download
M media/audio/virtual_audio_input_stream.h View 3 chunks +2 lines, -6 lines 0 comments Download
M media/audio/virtual_audio_input_stream.cc View 1 2 3 4 5 6 7 8 2 chunks +4 lines, -9 lines 0 comments Download
M media/audio/virtual_audio_input_stream_unittest.cc View 3 chunks +7 lines, -2 lines 0 comments Download
M media/audio/virtual_audio_output_stream_unittest.cc View 3 chunks +7 lines, -5 lines 0 comments Download
M media/cast/sender/video_encoder_impl.cc View 1 chunk +1 line, -1 line 0 comments Download
M ui/events/devices/device_data_manager.cc View 1 2 1 chunk +3 lines, -1 line 0 comments Download

Messages

Total messages: 11 (2 generated)
hubbe
5 years, 8 months ago (2015-04-24 18:52:37 UTC) #2
hubbe
5 years, 7 months ago (2015-04-30 22:25:44 UTC) #4
maniscalco
(drive-by question) When an object cannot be deleted on the thread on which it lives, ...
5 years, 7 months ago (2015-04-30 23:02:10 UTC) #5
chromium-reviews
If the foo thread is gone, how can it be unsafe to delete it on ...
5 years, 7 months ago (2015-04-30 23:05:09 UTC) #6
maniscalco
It depends on what the dtor does (and dtors of the member variables, and base ...
5 years, 7 months ago (2015-04-30 23:48:15 UTC) #7
chromium-reviews
Perhaps all threads should name a successor, which inherits all tasks when the thread dies. ...
5 years, 7 months ago (2015-05-04 22:53:26 UTC) #8
danakj
On Thu, Apr 30, 2015 at 4:05 PM, Fredrik Hubinette <hubbe@google.com> wrote: > If the ...
5 years, 7 months ago (2015-05-04 22:57:10 UTC) #9
danakj
On Mon, May 4, 2015 at 3:53 PM, Fredrik Hubinette <hubbe@google.com> wrote: > Perhaps all ...
5 years, 7 months ago (2015-05-04 23:12:19 UTC) #10
chromium-reviews
5 years, 7 months ago (2015-05-04 23:21:03 UTC) #11
It's probably not a big issue, but there are places which create and stop
threads on demand in the code. (Such as the cast library, and tests...) I'm
not sure what's worth doing, but the current state of threading in chrome
is a bit scary I think.

    /Hubbe

On Mon, May 4, 2015 at 4:05 PM, Dana Jansens <danakj@chromium.org> wrote:

> On Mon, May 4, 2015 at 3:53 PM, Fredrik Hubinette <hubbe@google.com>
> wrote:
>
>> Perhaps all threads should name a successor, which inherits all tasks
>> when the thread dies.
>>
>
> Maybe, but that's a lot more complicated than just having a weakptr. I
> guess you'd have to tell all your weakptrs where to look next and give the
> backrefs to the new thread so it could do the same.
>
> Is this a problem outside of shutdown? Maybe users of patterns like
> DeleteSoon should be (D)CHECKing that it succeeds, and we shouldn't just
> blindly allow leaks. Proper shutdown should not be impossible?
>
>
>> (Then we can implement our out little Game of Threads in chrome to see
>> who can own all the tasks.)
>>
>>    /Hubbe
>>
>>
>> On Mon, May 4, 2015 at 3:49 PM, Dana Jansens <danakj@chromium.org> wrote:
>>
>>> On Thu, Apr 30, 2015 at 4:05 PM, Fredrik Hubinette <hubbe@google.com>
>>> wrote:
>>>
>>>> If the foo thread is gone, how can it be unsafe to delete it on another
>>>> thread?
>>>>
>>>
>>> It's possible 2 objects are meant to be destroyed on the same thread but
>>> the threads gone, so they are destroyed in racy ways on 2 separate threads.
>>>
>>>
>>>>
>>>>     /Hubbe
>>>>
>>>>
>>>> On Thu, Apr 30, 2015 at 4:02 PM, <maniscalco@chromium.org> wrote:
>>>>
>>>>> (drive-by question)
>>>>>
>>>>> When an object cannot be deleted on the thread on which it lives, is
>>>>> it better
>>>>> to leak the object or invoke its dtor on the "wrong thread"?
>>>>>
>>>>> Say we've got an object that lives on the foo thread and should be
>>>>> deleted on
>>>>> the foo thread:
>>>>>
>>>>> // Assuming we're executing on some thread other than the foo thread.
>>>>> // Assuming old version of DeletePointer.
>>>>> // object is a scoped_ptr<Object>
>>>>> foo_task_runner->PostTask(FROM_HERE,
>>>>>     base::Bind(&base::DeletePointer<Object>, object.release()));
>>>>>
>>>>> If the foo thread exists, things are good and the object is deleted on
>>>>> the foo
>>>>> thread.  In the above code, if the foo thread doesn't exist, we leak
>>>>> the object.
>>>>>
>>>>> // Assuming new version of DeletePointer.
>>>>> foo_task_runner->PostTask(FROM_HERE,
>>>>>     base::Bind(&base::DeletePointer<Object>, object));
>>>>>
>>>>> With the new version of DeletePointer, what happens when the foo
>>>>> thread doesn't
>>>>> exist?  The PostTask will fail and the object will be deleted on the
>>>>> thread that
>>>>> attempted to PostTask (the "wrong thread").
>>>>>
>>>>> Leaking objects and destroying them on the wrong thread are both bad.
>>>>> Unless
>>>>> I'm misunderstanding, I believe this patch is trading one for the
>>>>> other.  IMO,
>>>>> when we don't know if it's safe to delete the object on the current
>>>>> thread,
>>>>> leaking seems like the lesser of two evils.  WDYT?
>>>>>
>>>>>
>>>>> https://codereview.chromium.org/1074963003/
>>>>>
>>>>
>>>>
>>>
>>
>

To unsubscribe from this group and stop receiving emails from it, send an email
to chromium-reviews+unsubscribe@chromium.org.

Powered by Google App Engine
This is Rietveld 408576698