This function creates a list, named q, on the stack. That object q is destroyed when you return from this function. If you want to return a pointer to an object, you will have to do something to ensure that the object exists after the function returns.
This is commonly done by creating the object before you call the function, and passing the object to the function using a pointer or as a reference, or you can create the object dynamically within the function using new such that it won't be destroyed until you delete it.
by Moschops: OP changed the code, so I had to change my answer.