[#444] io_write()/fwrite() and EINTR on Solaris — Jos Backus <jos@...>

I am encountering a problem similar to the one mentioned here,

19 messages 2002/09/06
[#453] Re: io_write()/fwrite() and EINTR on Solaris — nobu.nokada@... 2002/09/08

Hi,

[#454] Re: io_write()/fwrite() and EINTR on Solaris — matz@... (Yukihiro Matsumoto) 2002/09/09

Hi

[#469] Re: io_write()/fwrite() and EINTR on Solaris — Jos Backus <jos@...> 2002/09/09

On Mon, Sep 09, 2002 at 03:55:13PM +0900, Yukihiro Matsumoto wrote:

[#479] Re: io_write()/fwrite() and EINTR on Solaris — Jos Backus <jos@...> 2002/09/10

On Tue, Sep 10, 2002 at 01:04:10AM +0900, Jos Backus wrote:

[#492] Re: io_write()/fwrite() and EINTR on Solaris — Jos Backus <jos@...> 2002/09/21

On Wed, Sep 11, 2002 at 02:23:33AM +0900, Jos Backus wrote:

[RFC] Related to [Memleak] in sprintf.c

From: Michal Rokos <m.rokos@...>
Date: 2002-09-09 09:20:11 UTC
List: ruby-core #461
Hi,

	sometimes we cannot use ALLOCA and we have to use ALLOC. When
	the exception is raised in some ruby func, memory can leak.

	In these cases we can use some think like: (Example included
	below.)

		Michal

PS: I know that we can use rb_ensure, but it looks like overkill to me.

diff -u ../ruby-09-06/eval.c ./eval.c
--- ../ruby-09-06/eval.c	Fri Sep  6 20:55:37 2002
+++ ./eval.c	Sun Sep  8 17:47:34 2002
@@ -4240,6 +4240,29 @@
 }
 
 VALUE
+rb_when_raised_free(proc, data, arg)
+    VALUE (*proc)();
+    VALUE data;
+    void *arg;
+{
+    int state;
+    volatile VALUE result = Qnil;
+
+    PUSH_TAG(PROT_NONE);
+    if ((state = EXEC_TAG()) == 0) {
+	result = (*b_proc)(data1);
+    }
+    POP_TAG();
+    if (prot_tag) return_value(prot_tag->retval);
+
+    if (state) {
+	free(arg);
+	JUMP_TAG(state);
+    }
+    return result;
+}
+
+VALUE
 rb_with_disable_interrupt(proc, data)
     VALUE (*proc)();
     VALUE data;
diff -u ../ruby-09-06/sprintf.c ./sprintf.c
--- ../ruby-09-06/sprintf.c	Fri Sep  6 20:55:37 2002
+++ ./sprintf.c	Sun Sep  8 18:21:53 2002
@@ -335,7 +335,7 @@
 	      bin_retry:
 		switch (TYPE(val)) {
 		  case T_FLOAT:
-		    val = rb_dbl2big(RFLOAT(val)->value);
+		    val = rb_when_raised_free(rb_dbl2big(RFLOAT(val)->value), buf);
 		    if (FIXNUM_P(val)) goto bin_retry;
 		    bignum = 1;
 		    break;

-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Michal Rokos                         Czech Technical University, Prague
E-mail:m.rokos@sh.cvut.cz      ICQ:36118339      Jabber:majkl@jabber.cz
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

In This Thread

Prev Next