However, I wouldn't want all the dozens of apps on my desktop to all refuse to return memory back to the system just because they might want it again at some point in the future (thus unnecessarily forcing swapping to disk or a memory upgrade). Unless there is a very specific reason to think that performance is critical, my personal view is that it's polite for a userspace app to return memory back to the underlying system whenever it is reasonably possible.
malloc may or may not return memory to the system. Usually, it won't, except in fringe cases (eg 'large allocations' done via mmap). Memory allocations which originally happened by calling brk/sbrk cannot easily be returned to the system, anyway, only if freeing them happens to release a chunk of memory just below the current break.
On the contrary, usually it will. I'm revising my estimate of the quality of your "50 — 300 lines of code" implementation downwards as a result of this statement, because you are erroneously conflating allocating address space with committing pages. Most implementations that I am familiar with were written by people that didn't make this mistake.
My implementation (more correctly, one of my implementations (-

calls the OS/2 DosSetMem() function to commit partially used pages and de-commit wholly unused pages within the heap arena as necessary. Several Win32 implementations that I'm aware of call VirtualAlloc() to commit and de-commit pages within arenas. (For a good explanation of this process, see Matt Pietrek's dissection of the DOS-Windows 9x HeapAlloc() function in his
Windows 95 System Programming Secrets book.) The GNU C library version 2.11.1 calls madvise() with the MADV_DONTNEED flag for wholly unused pages.
The OS/2 and Win32 implementations are returning unused heap memory to the operating system as a matter of course. The GNU C library is intending to do the same, and is doing the best that it can with the more limited system API that it has to work with, and the operating system bugs that it has to cope with. (See, for example,
Linux kernel bug #6282, reported by Samuel Thibault in 2007.)