As Rich already suggested, you can pass the address of a local into setFunction instead of retuning it.
Depending on what TYPE is, the "setFunction" (quotes as it is more a get-function actually) could also return TYPE, and not TYPE*.
I would not go with static for various reasons, one is, as you noted, statics cannot be deallocated. Another reason is that there is only a single static instance ever, whereas with locals different function invocations have their own copy.
Using free/malloc is technically possible, but I would not do it on a small chip. Leaking memory can cause problematic bugs and it also makes the code harder to get correct as the caller now must remember to call free. Also dynamically allocated memory has to managed, that causes additional overhead.
Daniel
void main(void) {
TYPE MY_VAR;
setFunction(&MY_VAR);
anotherFunction();
}
void setFunction(TYPE* result) {
// ......
*result = ......
return;
}