On 8/10/06, Scott <drmemory@xxxxxxxxxxx> wrote:
With the caveat that I haven't done any serious programming in C for many years: As I recall, I always used a protocol halfway between these, as: char *func(size_t bufsiz) { char *retval = malloc (bufsiz); if (retval == NULL) return (NULL); /* whatever */ return (retval); }
It looks like this would lead to memory leaks that would be difficult to track down along a wide variety of code paths upon return. I recommend the first style: int func(char *buf, size_t bufsize). All malloc and frees are then encouraged to sandwich this call. David - : send the line "unsubscribe linux-c-programming" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html