Pretty basic question here, I'm a little unsure on the passing around of memory in C.

If I have the following

CGPoint* tileForCoordinates (CGPoint position, short width, short height)
{   
   CGPoint *tileCoordinate = (CGPoint*)malloc(sizeof(CGPoint));
   tileCoordinate->xTile = (position.xPosition / width);
   tileCoordinate->yTile = (position.yPosition / height);

   return tileCoordinate;
}

and I wanted to call this in another source file or whatever, would I declare a pointer and above and return it? If so, When I call is from another class e.g.

CGPoint *currentTilePosition = tileForCoordinates(curPosition, 50, 50);

What happens to the pointer returned by malloc? Should it be freed or whats the story? :)

Edit
Report