Skip to content

Commit

Permalink
Work around SANE leaking file descriptors at sane_exit()
Browse files Browse the repository at this point in the history
  • Loading branch information
Simul Piscator authored and Simul Piscator committed Nov 13, 2023
1 parent ef202ce commit 202fb79
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions sanecpp/sanecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ std::ostream log(nullptr);

option option_set::s_nulloption;

// we call sane_exit() as frequently as possible
// in order to minimize effects from bugs/leaks in backends
static int sane_init_refcount = 0;
static std::mutex sane_init_mutex;

Expand All @@ -89,6 +87,16 @@ sane_init_release()
}
}

init::init()
{
sane_init_addref();
}

init::~init()
{
sane_init_release();
}

option_set::option_set() {}

option_set::option_set(device_handle h)
Expand Down
6 changes: 6 additions & 0 deletions sanecpp/sanecpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ dtostr_c(double);
// will enable logging to stderr
extern std::ostream log;

struct init
{
init();
~init();
};

struct device_info
{
std::string name, vendor, model, type;
Expand Down
3 changes: 3 additions & 0 deletions server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct NetworkNotifier : NetworkHotplugNotifier
switch (ev) {
case addressArrived:
case addressLeft:
case addressChange:
std::clog << "network hotplug event, reloading configuration" << std::endl;
server.terminate(SIGHUP);
break;
Expand Down Expand Up @@ -267,6 +268,8 @@ Server::run()
std::shared_ptr<NetworkNotifier> pNetworkNotifier;
if (mNetworkhotplug)
pNetworkNotifier = std::make_shared<NetworkNotifier>(*this);

sanecpp::init saneinit;

bool ok = false, done = false;
do {
Expand Down

0 comments on commit 202fb79

Please sign in to comment.