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()
succeeded.

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
either.

Signed-off-by: Simon McVittie <smcv@collabora.com>
4 jobs for master in 7 minutes and 38 seconds (queued for 4 seconds)
Status Job ID Name Coverage
  Test
manual #38094
allowed to fail manual
build:arch
passed #38093
build:bionic

00:07:34

passed #38092
build:buster

00:07:17

passed #38091
build:stretch

00:07:38