Yes. Your example works fine, only the temporary variable is unnecessary. However it is valid.
If I remember correctly: the a1 variable is allocated, you do whatever the heck you want with it, then a copy of the int is returned while that int that you just made dies along with the functions temporary memory.