cef_client getters should be idempotent?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Re: cef_client getters should be idempotent?

Postby aleitner » Wed Nov 01, 2023 2:21 pm

Problem solved and we now have idempotent getters.

I've managed to solve the double-free error issue we were experiencing. The problem was related to the initial reference count of our singleton object in the getter function.

Previously, when testing we only incremented the reference count for subsequent gets, but not for the first one. This meant that the first time the getter was called, the object's reference count was at 1 (from the initialization), and when the caller finished with it and decremented the count, it reached zero and the object was freed prematurely.

The solution was to always increment the reference count whenever the getter is invoked, even for the first time. This effectively gives the singleton object two references the first time it's retrieved (one as the "base" reference and one from the first get). Subsequent "get" calls add to this count, and correspondingly, these are all reduced when the callers finish with the object.

Under this setup, we won't reach a count of zero (and thus won't free the object) until every caller has finished with it and we are cleaning up at the end of the process.
aleitner
Techie
 
Posts: 49
Joined: Fri Jun 16, 2023 12:05 pm

Previous

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 205 guests