summaryrefslogtreecommitdiff
path: root/dln.c
diff options
context:
space:
mode:
authormichal <michal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-09-05 09:17:48 +0000
committermichal <michal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-09-05 09:17:48 +0000
commit61ec0281a4327ef3d48eafa5f2b7eabffd9114e0 (patch)
tree2ceb59767f00ecbb1b9fae51bafd55e5ccd1bb68 /dln.c
parent5a53593f818fcdef000409799d8d1616c5964f8d (diff)
fix mem leaks (ruby-core:405, ruby-core:407)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dln.c')
-rw-r--r--dln.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/dln.c b/dln.c
index 90c5213..0d923f5 100644
--- a/dln.c
+++ b/dln.c
@@ -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,21 @@ 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) {\
+ free(*buf);\
+ rb_memerror();\
+ }\
+ strcpy(tmp, *buf);\
+ free(*buf);\
+ *buf = tmp;\
+} while (0)
+
#ifdef USE_DLN_A_OUT
#ifndef LIBC_NAME
@@ -646,8 +659,12 @@ load_1(fd, disp, need_init)
}
reloc = load_reloc(fd, &hdr, disp);
if (reloc == NULL) return -1;
+
syms = load_sym(fd, &hdr, disp);
- if (syms == NULL) return -1;
+ if (syms == NULL) {
+ free(reloc);
+ return -1;
+ }
sym = syms;
end = syms + (hdr.a_syms / sizeof(struct nlist));
@@ -871,7 +888,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 +1282,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 +1319,6 @@ dln_load(file)
}
init_fct = (void(*)())dlsym(handle, buf);
- free(buf);
if (init_fct == NULL) {
error = DLN_ERROR();
dlclose(handle);
@@ -1331,7 +1345,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 +1403,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 +1436,6 @@ dln_load(file)
/* NSLookupAndBindSymbol require function name with "_" !! */
init_fct = NSAddressOfSymbol(NSLookupAndBindSymbol(buf));
- free(buf);
(*init_fct)();
return (void*)init_fct;
@@ -1466,17 +1476,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 +1528,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);
}