From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Linas Vepstas Newsgroups: gmane.lisp.guile.user Subject: [PATCH 6/12] Guile-DBI: Fix crash, avoid recursive free Date: Fri, 19 Sep 2008 09:11:45 -0500 Message-ID: <20080919141145.GE13684@linas.org> References: <3ae3aa420809190645o2fe2b746id80f53c5cb123e5b@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="+SfteS7bOf3dGlBC" X-Trace: ger.gmane.org 1221833818 6544 80.91.229.12 (19 Sep 2008 14:16:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 19 Sep 2008 14:16:58 +0000 (UTC) Cc: Guile User Mailing List To: Maurizio Boriani Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Sep 19 16:17:55 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KgglE-0006Uq-Ke for guile-user@m.gmane.org; Fri, 19 Sep 2008 16:15:05 +0200 Original-Received: from localhost ([127.0.0.1]:38428 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KggkD-0008JO-5y for guile-user@m.gmane.org; Fri, 19 Sep 2008 10:14:01 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KggiB-0007hx-0S for guile-user@gnu.org; Fri, 19 Sep 2008 10:11:55 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kggi9-0007hH-9c for guile-user@gnu.org; Fri, 19 Sep 2008 10:11:54 -0400 Original-Received: from [199.232.76.173] (port=36478 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kggi9-0007hD-1d for guile-user@gnu.org; Fri, 19 Sep 2008 10:11:53 -0400 Original-Received: from rv-out-0708.google.com ([209.85.198.245]:40248) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Kggi8-00058g-CN for guile-user@gnu.org; Fri, 19 Sep 2008 10:11:52 -0400 Original-Received: by rv-out-0708.google.com with SMTP id k29so499119rvb.6 for ; Fri, 19 Sep 2008 07:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent:from; bh=hCi5feanplSX45wK04mzXddxUNvJFk8L+FXsB/6/aQo=; b=rQnfO4d+VHP6q3B3cwyLmFrg/QmnHXHkf1N2V912WiBbi5XN+RczaocXLd1pr6JAh/ SHOUBhMUc9giziTHKLQUIA620rVlAnUqMEnwFzO3vwg47DVP+PaEoXuvEiebwjom6H1t 9Q4V+sOzIqSQ89L86LHcfnppJGpIbBreiHKXU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:to:cc:subject:message-id:references:mime-version:content-type :content-disposition:in-reply-to:user-agent:from; b=AmAhS/OC9HppJZZHovU2126hk5bRxHZsINaLCdtyanOXbTkp5XndBlRZiV0byHTeAP +667WPGfKqqPFhXHChdX4szyH/04MTxJenJriyWal0rcJs/3MVQ4nM21nCTPCWnnFFsC GFCxgeQrs+tJoctSBSYmSQ9GL8TDQqcj6TWrQ= Original-Received: by 10.140.140.3 with SMTP id n3mr45336rvd.299.1221833511087; Fri, 19 Sep 2008 07:11:51 -0700 (PDT) Original-Received: from linas.org ( [67.100.217.179]) by mx.google.com with ESMTPS id 4sm1197627yxj.7.2008.09.19.07.11.49 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 19 Sep 2008 07:11:50 -0700 (PDT) Content-Disposition: inline In-Reply-To: <3ae3aa420809190645o2fe2b746id80f53c5cb123e5b@mail.gmail.com> User-Agent: Mutt/1.5.15+20070412 (2007-04-11) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6787 Archived-At: --+SfteS7bOf3dGlBC Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable There is a particularly nasty crash scenario invloving the=20 garbage collector. The problem is that the dbi free routine calls the dbi close routine, which tries to alloc new SCM nodes. This is bad, because one should not alloc while=20 the garbage collector is running. So add a flag, incidating that a free is in progress.=20 The DBD layers will have to honour this flag. (also fixes one more mem leak). Signed-off-by: Linas Vepstas --- include/guile-dbi/guile-dbi.h | 1 + src/guile-dbi.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) Index: guile-dbi-2.0.0/include/guile-dbi/guile-dbi.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- guile-dbi-2.0.0.orig/include/guile-dbi/guile-dbi.h 2008-09-16 21:36:22.= 000000000 -0500 +++ guile-dbi-2.0.0/include/guile-dbi/guile-dbi.h 2008-09-16 21:40:30.00000= 0000 -0500 @@ -34,6 +34,7 @@ typedef struct g_db_handle SCM closed; /* boolean, TRUE if closed otherwise FALSE */ void* handle; void* db_info; + int in_free; } gdbi_db_handle_t; /* end guile smob struct */ =20 Index: guile-dbi-2.0.0/src/guile-dbi.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- guile-dbi-2.0.0.orig/src/guile-dbi.c 2008-09-16 21:40:24.000000000 -0500 +++ guile-dbi-2.0.0/src/guile-dbi.c 2008-09-16 21:40:30.000000000 -0500 @@ -53,6 +53,8 @@ SCM_DEFINE (make_g_db_handle, "dbi-open" g_db_handle->bcknd =3D bcknd; g_db_handle->constr =3D conn_string; g_db_handle->handle =3D NULL; + g_db_handle->closed =3D SCM_BOOL_T; + g_db_handle->in_free =3D 0; g_db_handle->db_info =3D NULL; =20 bcknd_str =3D scm_to_locale_string (bcknd); @@ -189,6 +191,9 @@ free_db_handle (SCM g_db_handle_smob) struct g_db_handle *g_db_handle =3D NULL; =20 g_db_handle =3D (struct g_db_handle*)SCM_SMOB_DATA(g_db_handle_smob); + if (g_db_handle->in_free) return 0; + g_db_handle->in_free =3D 1; + close_g_db_handle(g_db_handle_smob); =20 if (g_db_handle !=3D NULL) @@ -325,7 +330,8 @@ __gdbi_dbd_wrap(gdbi_db_handle_t* dbh, c 20))) =3D=3D NULL) { free(bcknd); - dbh->status =3D (SCM) scm_cons(scm_from_int(errno), + if (dbh->in_free) return; /* do not SCM anything while in GC */ + dbh->status =3D scm_cons(scm_from_int(errno), scm_makfrom0str(strerror(errno))); return; } @@ -335,6 +341,8 @@ __gdbi_dbd_wrap(gdbi_db_handle_t* dbh, c if((ret =3D dlerror()) !=3D NULL) { free(bcknd); + free(func); + if (dbh->in_free) return; /* do not SCM anything while in GC */ dbh->status =3D (SCM) scm_cons(scm_from_int(1), scm_makfrom0str(ret)); return; @@ -345,8 +353,10 @@ __gdbi_dbd_wrap(gdbi_db_handle_t* dbh, c { free(bcknd); } + + if (dbh->in_free) return; /* do not SCM anything while in GC */ /* todo: error msg to be translated */ - dbh->status =3D (SCM) scm_cons(scm_from_int(0), + dbh->status =3D scm_cons(scm_from_int(0), scm_makfrom0str("symbol loaded")); return; } --+SfteS7bOf3dGlBC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iQEVAwUBSNOzIYSDRXfAOJJBAQLe0ggA3YKI6t2tqEh4L4H4nNAfg9bNvB9/RySe hN1GpOAIAaPkEcnDeUNEfB9x8u46Ec7GimSvmIcaFaePYEalIY+KuXjheq21s467 cVdR1ueWYTHx0/GAdIZjvDsTEiH9CS8nOz+PlV3mSEET2IVGz6Ccgg+gtT6+TtK1 0jhQ3bmLPJOk0uUEu/Tw/QQm0XcyoXWWPQ4ex3pifK/E6/im3L/7q5oZyyHio3yC Z4AQu8W/YIgQIDmUtPXPfxfwoOaGCViH3tYz2XUf4ZAd5ozRsx+NND6U8f567buB wZWt+zwFs6FhH/s7Svj4/M+vrRhwHySZOZVhjT3sh8Dw3OjDCqE9QQ== =Llvn -----END PGP SIGNATURE----- --+SfteS7bOf3dGlBC--