Skip to content

at_exit_handler failed to work when dso_handle is NULL #3467

@xiangzhai

Description

@xiangzhai

Hi,

Testcase failed to handle atexit to be called at normal process termination: debug.log

Reduced Testcase:

#include <stdio.h>
#include <stdlib.h>
void cleanup1(void) {
    printf("cleanup1 \n");
}
int main(void) {
    printf("main in \n");
    atexit(cleanup1);
    return 0;
}

Actual:

main in

Expected:

main in 
cleanup1

debug patch:

diff --git a/src/tools/cleanup.c b/src/tools/cleanup.c
index 79ac34518..cf0518ccb 100644
--- a/src/tools/cleanup.c
+++ b/src/tools/cleanup.c
@@ -28,8 +28,11 @@ void AddCleanup(x64emu_t *emu, void *p)
 void AddCleanup1Arg(x64emu_t *emu, void *p, void* a, elfheader_t* h)
 {
     (void)emu;
-    if(!h)
+    if (!h) {
+        printf_log(LOG_DEBUG, "%s:%d p=%p a=%p\n", __func__, __LINE__, p, a);
+        AddCleanup(emu, p);
         return;
+    }
 
     if(h->clean_sz == h->clean_cap) {
         h->clean_cap += 32;

debug.log

Thanks,
Leslie Zhai

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions