[#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:

Re: [MemLeak] in dln.c

From: Michal Rokos <m.rokos@...>
Date: 2002-09-02 16:09:11 UTC
List: ruby-core #405
Hello,

On Tue, Sep 03, 2002 at 12:00:42AM +0900, Yukihiro Matsumoto wrote:
> I'd use alloca.  I want dln.c to be separatable from Ruby as much as
> possible.

	So, #2 is a winner.

	(Only think that worries me is 'man alloca': The alloca function
	is machine and compiler dependent. Its use is discouraged.)

	All credits goes to nobu.

		Michal


Index: dln.c
===================================================================
RCS file: /src/ruby/dln.c,v
retrieving revision 1.38
diff -u -p -r1.38 dln.c
--- dln.c	2002/06/25 09:44:57	1.38
+++ dln.c	2002/09/02 16:00:55
@@ -103,8 +103,8 @@ int eaccess();
 # endif
 #endif
 
-static void
-init_funcname(buf, file)
+static int
+init_funcname_len(buf, file)
     char **buf;
     char *file;
 {
@@ -131,8 +131,18 @@ init_funcname(buf, file)
 	    *p = '\0'; break;
 	}
     }
+    return p - *buf;
 }
 
+#define init_funcname(buf, file) do {\
+    int len = init_funcname_len(buf, file);\
+    char *tmp = ALLOCA_N(char, len+1);\
+    if (!tmp) rb_memerror();\
+    strcpy(tmp, *buf);\
+    free(*buf);\
+    *buf = tmp;\
+} while (0)
+
 #ifdef USE_DLN_A_OUT
 
 #ifndef LIBC_NAME
@@ -871,7 +880,6 @@ load_1(fd, disp, need_init)
 		}
 	    }
 	}
-	free (buf);
 	if (libs_to_be_linked && undef_tbl->num_entries > 0) {
 	    while (*libs_to_be_linked) {
 		load_lib(*libs_to_be_linked);
@@ -1266,7 +1274,6 @@ dln_load(file)
     if ((init_fct = (void(*)())GetProcAddress(handle, buf)) == NULL) {
 	rb_loaderror("%s - %s\n%s", dln_strerror(), buf, file);
     }
-    free(buf);
 
     /* Call the init code */
     (*init_fct)();
@@ -1304,7 +1311,6 @@ dln_load(file)
 	}
 
 	init_fct = (void(*)())dlsym(handle, buf);
-	free(buf);
 	if (init_fct == NULL) {
 	    error = DLN_ERROR();
 	    dlclose(handle);
@@ -1331,7 +1337,6 @@ dln_load(file)
 	    rb_loaderror("%s - %s", strerror(errno), file);
 	}
 	shl_findsym(&lib, buf, TYPE_PROCEDURE, (void*)&init_fct);
-	free(buf);
 	if (init_fct == NULL) {
 	    shl_findsym(&lib, buf, TYPE_UNDEFINED, (void*)&init_fct);
 	    if (init_fct == NULL) {
@@ -1390,11 +1395,9 @@ dln_load(file)
 	if(rld_lookup(NULL, buf, &init_address) == 0) {
 	    rb_loaderror("Failed to lookup Init function %.200s", file);
 	}
-	free(buf);
 
 	 /* Cannot call *init_address directory, so copy this value to
 	    funtion pointer */
-
 	init_fct = (void(*)())init_address;
 	(*init_fct)();
 	return (void*)init_address;
@@ -1425,7 +1428,6 @@ dln_load(file)
 
 	/* NSLookupAndBindSymbol require function name with "_" !! */
 	init_fct = NSAddressOfSymbol(NSLookupAndBindSymbol(buf));
-	free(buf);
 	(*init_fct)();
 
 	return (void*)init_fct;
@@ -1466,17 +1468,14 @@ dln_load(file)
 
       if ((B_BAD_IMAGE_ID == err_stat) || (B_BAD_INDEX == err_stat)) {
 	unload_add_on(img_id);
-	free(buf);
 	rb_loaderror("Failed to lookup Init function %.200s", file);
       }
       else if (B_NO_ERROR != err_stat) {
 	char errmsg[] = "Internal of BeOS version. %.200s (symbol_name = %s)";
 	unload_add_on(img_id);
-	free(buf);
 	rb_loaderror(errmsg, strerror(err_stat), buf);
       }
 
-      free(buf);
       /* call module initialize function. */
       (*init_fct)();
       return (void*)img_id;
@@ -1521,7 +1520,6 @@ dln_load(file)
       /* Locate the address of the correct init function */
       c2pstr(buf);
       err = FindSymbol(connID, buf, &symAddr, &class);
-      free(buf);
       if (err) {
 	  rb_loaderror("Unresolved symbols - %s" , file);
       }
-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Michal Rokos                         Czech Technical University, Prague
E-mail:m.rokos@sh.cvut.cz      ICQ:36118339      Jabber:majkl@jabber.cz
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

In This Thread