Fix leaks on realloc() failures #3005
Fix a few
This extends and replaces #2997 with additional fixes of the same kind in the examples as the one submitted there. The second commit fixes a memleak in darwinssl which was found by looking at this PR.
@CrazyHackGUT I've editorialized your commit a bit by fixing the other copy/paste