Ongy / netlink-hs

Netlink communication for Haskell
BSD 3-Clause "New" or "Revised" License
2 stars 7 forks source link

No clean way to close NL80211Socket #13

Open paulfertser opened 4 years ago

paulfertser commented 4 years ago

Hello, while working on https://github.com/jaor/xmobar/pull/429 I stumbled upon a resource leak as makeNL80211Socket was called many times until the OS limit was reached. The documentation of makeNL80211Socket (and other functions in this library that return a socket) didn't remind me that I need to somehow manually take care of releasing this resource. Moreover, NL80211Socket is opaque, and so I can't find a way to use System.Linux.Netlink.closeSocket with it.

I propose to add appropriate helpers like withFile or https://hackage.haskell.org/package/ncurses-0.2.16/docs/src/UI.NCurses.html#runCurses for automatic resource handling and to make it clear in the documentation that they're the preferred way to avoid leaks.