From nobody@FreeBSD.org  Thu Sep 19 06:27:46 2002
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 4AFC537B401
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 19 Sep 2002 06:27:46 -0700 (PDT)
Received: from www.freebsd.org (www.FreeBSD.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 07D9043E75
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 19 Sep 2002 06:27:46 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.6/8.12.6) with ESMTP id g8JDRj7R072148
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 19 Sep 2002 06:27:45 -0700 (PDT)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.6/8.12.6/Submit) id g8JDRjlX072147;
	Thu, 19 Sep 2002 06:27:45 -0700 (PDT)
Message-Id: <200209191327.g8JDRjlX072147@www.freebsd.org>
Date: Thu, 19 Sep 2002 06:27:45 -0700 (PDT)
From: Christophe Vedel <cv@validy.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: dlclose gives "invalid shared object handle" when called through the fini function of another module
X-Send-Pr-Version: www-1.0

>Number:         42956
>Category:       kern
>Synopsis:       [libc] dlclose gives "invalid shared object handle" when called through the fini function of another module
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 19 06:30:03 PDT 2002
>Closed-Date:    Mon Nov 08 15:00:58 UTC 2010
>Last-Modified:  Mon Nov 08 15:00:58 UTC 2010
>Originator:     Christophe Vedel
>Release:        4.6-RELEASE
>Organization:
Validy
>Environment:
FreeBSD freebsd46.home.org 4.6-RELEASE FreeBSD 4.6-RELEASE #0: Tue Jun 11 06:14:12 GMT 2002     murray@builder.freebsdmall.com:/usr/src/sys/compile/GENERIC  i386
      
>Description:
Dlopened ELF module A dlopens ELF module B and keeps a handle to it in a
static C++ object. When the process exits, rtld_exit is called and the fini
function for A is called. This function calls the object static destructor
and it tries to dlclose the handle to B. This gives a "invalid shared object
handle" message because the refcount field for the handle is zero.

All refcount fields have been set to zero in rtld_exit so that
objlist_call_fini calls all fini functions.     
>How-To-Repeat:
dlclose a valid shared object handle from the fini function of another
dynamically loaded shared object
>Fix:
possible fix: in libebxec/rtld-elf/rtld.c, add a "force" parameter to
objlist_call_fini to be able to force the calls to fini even when refcount
is not zero. In rtld_exit, do not zero the refcount fields, instead set
the force parameter to one when calling objlist_call_fini. In dlclose,
set the force parameter to zero.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: jh 
State-Changed-When: Mon Nov 8 15:00:56 UTC 2010 
State-Changed-Why:  
Fixed in r194531 is far as I can see. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=42956 
>Unformatted:
