Yes, it is. The first one creates an object on the stack and return its address. When the function returns the stack unwinds and the object gets destroyed. Therefore the caller ends up with a dangling pointer.
The second allocates an object on the heap and returns the address. The object is valid and will continue to be so until the caller explicitly deletes it.
You should never do the first approach!