if this is a bad idea, how to allocate memory in the function?
It's not a bad idea if you just keep it consistent in your own style.
A good approach is to pass the allocated memory to the caller that can then free it when its done. Something like this:
void my_new(char **obj) {
*obj = malloc(somesize);
}
and then call this from your function like this:
char *obj;
my_new(&obj);
/* work on obj */
free(obj)