unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Memory leak in scm_c_eval_string?
@ 2005-12-16 15:45 Michael J. Barillier
  2005-12-16 23:16 ` Kevin Ryde
  0 siblings, 1 reply; 3+ messages in thread
From: Michael J. Barillier @ 2005-12-16 15:45 UTC (permalink / raw)


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-12-19 17:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-16 15:45 Memory leak in scm_c_eval_string? Michael J. Barillier
2005-12-16 23:16 ` Kevin Ryde
2005-12-19 17:10   ` Michael J. Barillier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).