[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Memory leak in scm_c_eval_string?

From: Michael J. Barillier
Subject: Memory leak in scm_c_eval_string?
Date: Fri, 16 Dec 2005 09:45:35 -0600
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

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

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

thx -

Michael J. Barillier   ///
.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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]