Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

[linux-port] fix refcounting on imalloc and others - #200

Merged
ehsannas merged 1 commit into
google:linuxfrom
pow2clk:pow2clk-fixup
May 22, 2018
Merged

ehsannas merged 1 commit into
google:linuxfrom
pow2clk:pow2clk-fixup

Conversation

@pow2clk

@pow2clk pow2clk commented May 21, 2018

Copy link
Copy Markdown

The previous macro for InterlockedIncrement and InterlockedDecrement
didn't affect the parameter, rather it only returned the correct
result. This caused some subtle memory leaks, that, when fixed,
caused segfaults because an IMalloc structure was being used after
it had been freed because a refcount increment was missing during
CoGetMalloc, which allocates a brand new malloc and assigns it to
the given parameter, which creates a new reference.

Specifically, in the run I was debugging, DxcCreateBlobFromFile
created a null CComPtr, which it almost immediately assigned IMalloc
to, but since CoGetMalloc didn't increment the refcount, when the
function ended, the CComPtrBase destructor decremented the count
on the IMalloc without a corresponding increment when it was associated
with the CComPtr. So it got freed just a bit early, causing a segfault.

Prerequisite for #198
Though it's not directly related, but the change for that would
introduce the segfault otherwise and I prefer to discuss these
changes independently.

@AppVeyorBot

Copy link
Copy Markdown

Comment thread lib/DxcSupport/FileIOHelper.cpp Outdated

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. I'll fix this in a future version.

Comment thread lib/DxcSupport/FileIOHelper.cpp Outdated

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too.

@ehsannas

Copy link
Copy Markdown

Are you changing the SPIR-V Tools version?

@pow2clk

pow2clk commented May 22, 2018

Copy link
Copy Markdown
Author

not intentionally. I'll fix it with the other mistakes. Is there anything else I should change?

The previous macro for InterlockedIncrement and InterlockedDecrement
didn't affect the parameter, rather it only returned the correct
result. This caused some subtle memory leaks, that, when fixed,
caused segfaults because an IMalloc structure was being used after
it had been freed because a refcount increment was missing during
CoGetMalloc, which allocates a brand new malloc and assigns it to
the given parameter, which creates a new reference.

Specifically, in the run I was debugging, DxcCreateBlobFromFile
created a null CComPtr, which it almost immediately assigned IMalloc
to, but since CoGetMalloc didn't increment the refcount, when the
function ended, the CComPtrBase destructor decremented the count
on the IMalloc without a corresponding increment when it was associated
with the CComPtr. So it got freed just a bit early, causing a segfault.

Prerequisite for google#198
Though it's not directly related, but the change for that would
introduce the segfault otherwise and I prefer to discuss these
changes independently.

@ehsannas ehsannas left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One of Travis jobs has reached the time limit.

@pow2clk

pow2clk commented May 22, 2018

Copy link
Copy Markdown
Author

sigh 😞 Can you restart it for me? Or shall I resubmit?

@AppVeyorBot

Copy link
Copy Markdown

@ehsannas

Copy link
Copy Markdown

No need. LGTM

@ehsannas
ehsannas merged commit a7032ea into google:linux May 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants