-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix parent refcount (huge memory leak) on non-last thread exit #51
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1179,10 +1179,10 @@ void object_unref(void *objptr) | |
if (!obj) { | ||
return; | ||
} | ||
g_assert(obj->ref > 0); | ||
g_assert(qatomic_mb_read(&obj->ref) > 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. object_unref in current QEMU is still the same of this one
If you spotted a bug in QEMU you should report to them There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
/* parent always holds a reference to its children */ | ||
if (qatomic_fetch_dec(&obj->ref) == 1) { | ||
if (qatomic_dec_fetch(&obj->ref) == 0) { | ||
object_finalize(obj); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at current QEMU, this should be done before unlocking clone_lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the thing is that:
from comments in object_initialize_child_with_propsv():
next, when thread done, obj->ref == 2;
We doing just single obj_unref(), which leads to:
if (qatomic_fetch_dec(&obj->ref) == 1) {
, which executed asif (2 == 1)
,and decreasing obj->ref by one, after fetch...
So, the
cpu
object, which is analogue totask_struct
kernel object, still allocated and forgotten.Moreover, even if we pass this branch, then in
static void object_finalize(void *data)
we haveg_assert(obj->parent == NULL);
which expect no-linkage to parent.Finally, we remove linkage to parent while holding a lock, and freeing (unknown to parent now) object without.