SQLite Forum

warning: function may return address of local variable [-Wreturn-local-addr]
Login
A parse tree is being constructed.  The job of the sqlite3SelectNew() routine
is to takes a bunch of subtrees as input (the pararameters to the
sqlite3SelectNew() call), allocate a new SELECT object,
attach the subtress to the Select object, then returns the new Select
object.  Ownership of the subtrees passes from the caller into the new
Select object.

If an out-of-memory (OOM) error occurs, sqlite3SelectNew() should return NULL.
But before doing so, it also has to free all of the substructure that was
passed in as parameters (because it owns it).  The easiest way to delete all
that substructure is to load it all into a Select object, and invoke the
destructor on that Select object.  But if the OOM occurred while allocating
the Select object itself, what can you use to load the substructure into?

Solution:  Load the substructure into a Select object on the stack, and
call the destructor for that Stack object instead.  The destructor in this
case is the clearSelect() routine.  clearSelect() always frees the substructure,
but it only frees the Select object itself if the second parameter is true.
That parameter is false when we are deleting the stack-based Select object,
since obviously it would be a problem if you tried to free an object on the
stack.

So the "`standin`" variable is used (though rarely - only when an OOM occurs),
and it could in theory be used simultaneously by two different threads.  So
it cannot be static.