Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upSafer methods for wrapping CF references #185
Closed
Labels
Comments
|
Done! |
ChrisParis
pushed a commit
to ChrisParis/servo
that referenced
this issue
Sep 7, 2014
TestTWF, Asterisk-works: the test of input type=date
glennw
pushed a commit
to glennw/servo
that referenced
this issue
Jan 16, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I ran into a bug earlier where a CF wrapper in CoreText had accidentally called CFRelease on something that was not owned (i.e., followed the "Get" rule instead of "Copy" rule according to Core Foundation Ownership Rules). This is because it was wrapped without a call to CFRetain.
There are two ways to fix this, and each require separate wrap methods
wrap_ownedandwrap_borrowed. The simplest way is to call CFRetain forwrap_borrowed()and notwrap_owned(). This way, even non-owned things will have balanced refcounts when the wrapper is destroyed and calls CFRelease in the dtor.The other option is to customize dtor behavior so that only owned CF references have their refcounts reduced, by parameterizing over WrapperType impl. This seems more complex, and is definitely not sound if we store the wrapper into a field somewhere---the owner of the reference could deallocate and leave the wrapper with a dangling pointer.