[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Module support: No environment in pointer release function

From: Philipp Stephani
Subject: Re: Module support: No environment in pointer release function
Date: Sun, 26 Feb 2017 16:23:47 +0000

Elias Mårtenson <address@hidden> schrieb am Fr., 10. Feb. 2017 um 06:21 Uhr:
On 9 February 2017 at 01:03, Andreas Politz <address@hidden> wrote:
Elias Mårtenson <address@hidden> writes:

> [...] In it, I have to use the make_user_ptr() function in a few
> places. When creating a user_ptr, the function accepts a pointer to a
> function which will be called when the object is GC'ed.

How do you even know its your pointer and not someone elses ?

Because it was me who created the pointer. In the specific case, when I call the GSSAPI function gss_import_name(), this function returns a pointer to an opaque object which needs to be released using the function gss_release_name().

I package up this pointer using env->make_user_pointer() which accept a function that is responsible for freeing the pointer when it's GC'ed.

The issue is that gss_import_name() can return an error. Of course, I've never actually seen it return an error, and I doubt that it ever will in practice. But I'm struggling with the correct way to handle an error. At the very least, I want to know it happened since that would reveal a bug in my code.

Right now I simply call abort() if there is an error. Excessive, I know, but at least I know when there is a problem and the stack trace gives me all the answers I need.

I'm not sure I should keep the abort() in the final version though.

Probably not. You should either log (on stderr) and ignore the error, or not call gss_release_name (or any other function that can fail) in a finalizer.
Just like they Java counterpart, finalizers can't fail. There's also no guarantee that they ever be called, or when they are called, so you shouldn't use them to implement cleanup that has to be deterministic or can fail.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]