From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Michael J. Barillier" Newsgroups: gmane.lisp.guile.devel Subject: Memory leak in scm_c_eval_string? Date: Fri, 16 Dec 2005 09:45:35 -0600 Message-ID: <877ja53v1c.fsf@shadizar.blackwolfinfosys.net> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1134763075 24926 80.91.229.2 (16 Dec 2005 19:57:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 16 Dec 2005 19:57:55 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Dec 16 20:57:46 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EnLhG-0004Z1-Q8 for guile-devel@m.gmane.org; Fri, 16 Dec 2005 20:56:56 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EnLhw-0004Ay-T5 for guile-devel@m.gmane.org; Fri, 16 Dec 2005 14:57:37 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EnHmt-0001rT-U6 for guile-devel@gnu.org; Fri, 16 Dec 2005 10:46:28 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EnHmr-0001q5-Tr for guile-devel@gnu.org; Fri, 16 Dec 2005 10:46:26 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EnHmq-0001p7-4d for guile-devel@gnu.org; Fri, 16 Dec 2005 10:46:24 -0500 Original-Received: from [65.24.5.135] (helo=ms-smtp-01-eri0.ohiordc.rr.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EnHpH-0008QX-IQ for guile-devel@gnu.org; Fri, 16 Dec 2005 10:48:55 -0500 Original-Received: from shadizar.blackwolfinfosys.net (cpe-24-92-90-108.midsouth.res.rr.com [24.92.90.108]) by ms-smtp-01-eri0.ohiordc.rr.com (8.12.10/8.12.7) with ESMTP id jBGFjYEo029862 for ; Fri, 16 Dec 2005 10:45:35 -0500 (EST) Original-Received: from localhost (localhost [127.0.0.1]) by shadizar.blackwolfinfosys.net (Postfix) with ESMTP id C87AB1C009 for ; Fri, 16 Dec 2005 09:45:36 -0600 (CST) Original-Received: from shadizar.blackwolfinfosys.net ([127.0.0.1]) by localhost (blackwolfinfosys.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 07309-03 for ; Fri, 16 Dec 2005 09:45:35 -0600 (CST) Original-Received: by shadizar.blackwolfinfosys.net (Postfix, from userid 1000) id 3889F1C044; Fri, 16 Dec 2005 09:45:35 -0600 (CST) Original-To: guile-devel@gnu.org User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux) X-Virus-Scanned: Symantec AntiVirus Scan Engine X-Virus-Scanned: amavisd-new at blackwolfinfosys.net X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:5534 Archived-At: I'd appreciate someone confirming that scm_c_eval_string doesn't leak memory. From strports.c: ,---- | SCM | scm_c_eval_string (const char *expr) | { | return scm_eval_string (scm_makfrom0str (expr)); | } `---- (NB: This is from guile-1.6.7 - the CVS version has scm_makfrom0str deprecated/discouraged.) My concern is the cell returned from scm_makfrom0str, which would be stack-resident as a temporary value. Scm_makfrom0str does a malloc to allocate memory for expr, so if I was to do something like: scm_c_eval_string("(display \"foo\")"); scm_c_eval_string("(display \"bar\")"); the stack frame created for the first call to scm_c_eval_string would be overlaid on the second invocation, and the temporary cell created in the first call overwritten so that the pointer from the first malloc is lost and the memory allocated to hold "(display \"foo\")" leaked. Am I needlessly worrying about this? Additionally, within a Guile extension how can I handle cells returned from library functions that are effectively thrown away? e.g.: SCM_DEFINE( example, "example", 0, 0, 0, (), "Example." ) #define FUNC_NAME s_example { SCM tmp; int n; tmp = scm_c_eval_string("(list \"foo\" \"bar\" \"baz\")"); n = do_something_with_tmp(tmp); return SCM_MAKINUM(n); } #undef FUNC_NAME Will the list returned from scm_c_eval_string be garbage-collected, or leaked? thx - -- Michael J. Barillier /// http://www.blackwolfinfosys.net/~blackwolf/ .O. | ``Experience with many protocols has shown that protocols with ..O | few options tend towards ubiquity, whereas protocols with many OOO | options tend towards obscurity.'' -- RFC 2821 _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel