Re: [PATCH pseudo 4/4] Do not return address of local variable


Andre McCurdy
 

On Wed, Jul 28, 2021 at 1:16 PM Seebs <seebs@...> wrote:

On Wed, 28 Jul 2021 11:36:22 +0200
"Damian Wrobel" <dwrobel@...> wrote:

Do I correctly assume that pseudo_client_op() has to be fully
reentrant?
No. It's never been even a tiny bit reentrant. We used to do the
allocate and free thing, and it was incredibly expensive, and the
nature of the thing requires confidence that we never, ever, have
more than one thing writing and reading over the socket at a time,
so it's just Not Reentrant. During one call to pseudo_client_op,
there will never be another, and all the IPC stuff uses a single
consistent local buffer that it returns the address of.

Declaring that as static without changing the initializer would indeed
break everything -- we rely on the initializer working. Changing it to
static means it only gets initialized once...

Changing it to:

static pseudo_msg_t msg;
msg = pseudo_msg_t { .type = PSEUDO_MSG_OP };

would probably be fine, because then it'd be initialized. Otherwise,
we'd get failures when msg got overwritten and reused.

Or just changing `result = &msg` to something like `result =
&xattrdb_data`, which would be nonsensical but it turns out not to
matter, as the only caller that reaches this case is the caller
that's just checking yes/no "is the return value not a null pointer".
If the caller only cares about yes/no then how about returning 1/0
instead of a pointer?

Join openembedded-core@lists.openembedded.org to automatically receive all group messages.