git: 452c5e9995ab - main - fdlopen(3): do not create a new object mapping if already loaded

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 22 Feb 2024 01:27:54 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=452c5e9995ab4cd6c7ea230cffe0c53bfa65c1ab

commit 452c5e9995ab4cd6c7ea230cffe0c53bfa65c1ab
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-02-22 01:18:06 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-02-22 01:27:09 +0000

    fdlopen(3): do not create a new object mapping if already loaded
    
    This is expected behavior for both dlopen(3) and fdlopen(3).
    
    PR:     277169
    Reviewed by:    emaste
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D44019
---
 libexec/rtld-elf/rtld.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 7d6b8ae52703..30ed48b5c615 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -2752,8 +2752,9 @@ load_object(const char *name, int fd_u, const Obj_Entry *refobj, int flags)
 	if (obj->ino == sb.st_ino && obj->dev == sb.st_dev)
 	    break;
     }
-    if (obj != NULL && name != NULL) {
-	object_add_name(obj, name);
+    if (obj != NULL) {
+	if (name != NULL)
+	    object_add_name(obj, name);
 	free(path);
 	close(fd);
 	return (obj);