Patrycja Szabłowska
1 min readFeb 10, 2018

--

Thanks for the article. The second example (Calling defer in the wrong order) inspired me to try to break http.Get() with infinite redirects. Despite my efforts it doesn’t leak file descriptors — Mathias Fredriksson was right about it.

Here’s the code — it’s a handler func which counts and follows redirects:
https://play.golang.org/p/HwV0gDN3NTE

So it’s unnecessary to check if res != nil before calling defer res.Body.Close().

--

--