From fc9f0030777d3a7c774d8abf57e274e5089236ad Mon Sep 17 00:00:00 2001 From: Jannick Date: Sun, 13 Dec 2020 00:38:31 +0100 Subject: [PATCH 1/2] ldd.cc: bug fix - handle case when dll dependencies are not found This commit should ensure that if a dll dependency is not found - it is shown in the list marked with 'not found' - LDD returns with exit code 1 * winsup/utils/ldd.cc: - enhance debug event EXIT_PROCESS_DEBUG_EVENT --- winsup/utils/ldd.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/winsup/utils/ldd.cc b/winsup/utils/ldd.cc index 4f3e769a32..590bbfb3a1 100644 --- a/winsup/utils/ldd.cc +++ b/winsup/utils/ldd.cc @@ -407,6 +407,13 @@ report (const char *in_fn, bool multiple) } break; case EXIT_PROCESS_DEBUG_EVENT: + if (ev.u.ExitProcess.dwExitCode != 0) + { + /* All dll dependencies were NOT found. */ + process_fn = fn_win; + res = 1; + } + print_and_exit: print_dlls (&dll_list, isdll ? fn_win : NULL, process_fn); exitnow = true; From cf63a5f57074142da58310ca934d7e02dc61c4eb Mon Sep 17 00:00:00 2001 From: Jannick Date: Sun, 13 Dec 2020 12:03:53 +0100 Subject: [PATCH 2/2] ldd.cc: fix memory leakage * winsup/utils/ldd.cc: here. --- winsup/utils/ldd.cc | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/winsup/utils/ldd.cc b/winsup/utils/ldd.cc index 590bbfb3a1..bb71646a47 100644 --- a/winsup/utils/ldd.cc +++ b/winsup/utils/ldd.cc @@ -123,6 +123,19 @@ static struct filelist char *name; } *head; +static void +destroy_filelist (struct filelist **phead) +{ + struct filelist *next, *head = *phead; + while (head) { + next = head->next; + free (head->name); + free (head); + head = next; + } + *phead = NULL; +} + static bool saw_file (char *name) { @@ -248,6 +261,18 @@ struct dlls struct dlls *next; }; +static void +destroy_dlls (struct dlls *dlls) +{ + struct dlls* next; + while (dlls) { + next = dlls->next; + free (dlls); + dlls = next; + } + +} + #define SLOP strlen (" (?)") char * tocyg (wchar_t *win_fn) @@ -280,7 +305,7 @@ tocyg (wchar_t *win_fn) static int print_dlls (dlls *dll, const wchar_t *dllfn, const wchar_t *process_fn) { - head = NULL; /* FIXME: memory leak */ + destroy_filelist(&head); while ((dll = dll->next)) { char *fn; @@ -430,6 +455,9 @@ report (const char *in_fn, bool multiple) break; } + /* cleanup */ + destroy_dlls(dll_list.next); + return res; }