cheery / node-udev

Bindings to libudev
35 stars 31 forks source link

unref assertion failing in some versions of libudev #37

Closed alejandroclaro closed 2 years ago

alejandroclaro commented 2 years ago

Looks like there is an incorrect reference counting management with libudev in line 180 of udev.cc

image

According to the documentation:

https://manpages.debian.org/testing/libudev-dev/udev_device_get_parent.3.en.html

The function udev_device_get_parent do not increment the reference, and the child node have a reference to the returned device. In some version of libudev, this triggers an assertion and the program is aborted:

Assertion 'p->n_ref > 0' failed at src/libudev/libudev-device.c:502, function udev_device_unref(). Aborting.

Changing the code around line 180 to this seems to fix the issue:

  udev_device *parentDev = udev_device_get_parent(dev.get());

  if (!parentDev) {
    return env.Null();
  }

  Napi::Object obj = Napi::Object::New(env);
  PushProperties(env, obj, parentDev);
  const char *path = udev_device_get_syspath(parentDev);
alejandroclaro commented 2 years ago

Pull request with a proposed fix: fix bad udev_device_get_parent unref #38

cheery commented 2 years ago

Hi, I reviewed, applied your patch and published it. We're done here, I guess?

alejandroclaro commented 2 years ago

Thanks @cheery we will test it again.

alejandroclaro commented 2 years ago

@cheery I can confirm it's working now. We have been testing for some days and everything is fine now. Thanks!