In this... abomination, "she waved at the screen," passing a NULL pointer is a programming error, as the documentation for the function clearly states.
When strdup is called in foo , the namestr variable value is overwritten, thereby losing the pointer to the memory allocated in main , and that causes the leak.