ld-libs: Always clear ldlibs->needed entry if ld_lib_open() fails

This is what was documented to happen.

Previously, we did not clear the entry if we failed to open the
library fd, or if we succeeded but the library was "unacceptable"
(wrong ELF class or machine tag). Normally this results in a minor
memory leak, and a fd leak if the library is "unacceptable".

However, when called from search_ldcache_cb(), it's particularly
important that we do this, because search_ldcache() uses the state
of the fd field - valid fd or not - to check whether ld_lib_open()

One practical symptom is that if your container has an x86_64
libfoo.so.0 that compares newer than the provider's libfoo.so.0,
and does not have an i386 libfoo.so.0, then capsule-capture-libs
would unexpectedly not capture the i386 libfoo.so.0 from the provider

Signed-off-by: Simon McVittie <smcv@collabora.com>
4 jobs for unacceptable in 8 minutes and 48 seconds (queued for 2 seconds)
Status Name Job ID Coverage
manual build:arch #38088
allowed to fail manual
passed build:bionic #38087


passed build:buster #38086


passed build:stretch #38085