[omniORB] Bad magic in CORBA::Environment object.

Duncan Grisby duncan at grisby.org
Thu Apr 15 18:47:53 BST 2004


On Saturday 10 April, Alex Tingle wrote:

> Here's a code fragment that illustrates the problem (The full method is
> in the attachment):
> 
>   if(!CORBA::is_nil(_req) && _req->poll_response())
>   {
>     CORBA::Environment_var env=_req->env();
>     if(!CORBA::Environment::PR_is_valid(env.in()))
>     {
> A:    cerr<<"EEK!!"<<endl;
>     }
> B:  else if(!CORBA::is_nil(env) && env->exception())
>     {
>       ...
> 
> Without the check for PR_is_valid(), the program core dumps at B).
> is_nil() returns false (as it always does when the object has bad
> magic), and then the call to environment() causes a SEGV.

I assume you mean the call to exception().

I think you have your memory management wrong. Section 1.30.4 of the
C++ mapping (version 1.1) says "Ownership of the return values of the
target, operation, arguments, result, env, exceptions, contexts, and
ctx functions is maintained by the Request; these return values must
not be freed by the caller".  You are assigning the result of env() to
a _var, meaning you are releasing it when you shouldn't. That's
probably the reason you manage to get hold of a bad environment
object.

> One further question: Why does CORBA::is_nil(x) return `false' when x
> has bad magic? I would have thought that `true' would have been a safer
> result.

If it's invalid, it's not nil!

Cheers,

Duncan.

-- 
 -- Duncan Grisby         --
  -- duncan at grisby.org     --
   -- http://www.grisby.org --



More information about the omniORB-list mailing list