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
This commit is contained in:
parent
5a53593f81
commit
61ec0281a4
@ -1,3 +1,8 @@
|
|||||||
|
Thu Sep 5 17:18:22 2002 Michal Rokos <michal@ruby-lang.org>
|
||||||
|
|
||||||
|
* dln.c: fix memory leak in dln_load (ruby-core:405) and
|
||||||
|
in load_1 (ruby-core:407)
|
||||||
|
|
||||||
Thu Sep 5 13:09:22 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
Thu Sep 5 13:09:22 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
* eval.c (rb_eval): overriding false constant with class/module
|
* eval.c (rb_eval): overriding false constant with class/module
|
||||||
|
34
dln.c
34
dln.c
@ -103,8 +103,8 @@ int eaccess();
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static int
|
||||||
init_funcname(buf, file)
|
init_funcname_len(buf, file)
|
||||||
char **buf;
|
char **buf;
|
||||||
char *file;
|
char *file;
|
||||||
{
|
{
|
||||||
@ -131,8 +131,21 @@ init_funcname(buf, file)
|
|||||||
*p = '\0'; break;
|
*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
|
#ifdef USE_DLN_A_OUT
|
||||||
|
|
||||||
#ifndef LIBC_NAME
|
#ifndef LIBC_NAME
|
||||||
@ -646,8 +659,12 @@ load_1(fd, disp, need_init)
|
|||||||
}
|
}
|
||||||
reloc = load_reloc(fd, &hdr, disp);
|
reloc = load_reloc(fd, &hdr, disp);
|
||||||
if (reloc == NULL) return -1;
|
if (reloc == NULL) return -1;
|
||||||
|
|
||||||
syms = load_sym(fd, &hdr, disp);
|
syms = load_sym(fd, &hdr, disp);
|
||||||
if (syms == NULL) return -1;
|
if (syms == NULL) {
|
||||||
|
free(reloc);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
sym = syms;
|
sym = syms;
|
||||||
end = syms + (hdr.a_syms / sizeof(struct nlist));
|
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) {
|
if (libs_to_be_linked && undef_tbl->num_entries > 0) {
|
||||||
while (*libs_to_be_linked) {
|
while (*libs_to_be_linked) {
|
||||||
load_lib(*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) {
|
if ((init_fct = (void(*)())GetProcAddress(handle, buf)) == NULL) {
|
||||||
rb_loaderror("%s - %s\n%s", dln_strerror(), buf, file);
|
rb_loaderror("%s - %s\n%s", dln_strerror(), buf, file);
|
||||||
}
|
}
|
||||||
free(buf);
|
|
||||||
|
|
||||||
/* Call the init code */
|
/* Call the init code */
|
||||||
(*init_fct)();
|
(*init_fct)();
|
||||||
@ -1304,7 +1319,6 @@ dln_load(file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
init_fct = (void(*)())dlsym(handle, buf);
|
init_fct = (void(*)())dlsym(handle, buf);
|
||||||
free(buf);
|
|
||||||
if (init_fct == NULL) {
|
if (init_fct == NULL) {
|
||||||
error = DLN_ERROR();
|
error = DLN_ERROR();
|
||||||
dlclose(handle);
|
dlclose(handle);
|
||||||
@ -1331,7 +1345,6 @@ dln_load(file)
|
|||||||
rb_loaderror("%s - %s", strerror(errno), file);
|
rb_loaderror("%s - %s", strerror(errno), file);
|
||||||
}
|
}
|
||||||
shl_findsym(&lib, buf, TYPE_PROCEDURE, (void*)&init_fct);
|
shl_findsym(&lib, buf, TYPE_PROCEDURE, (void*)&init_fct);
|
||||||
free(buf);
|
|
||||||
if (init_fct == NULL) {
|
if (init_fct == NULL) {
|
||||||
shl_findsym(&lib, buf, TYPE_UNDEFINED, (void*)&init_fct);
|
shl_findsym(&lib, buf, TYPE_UNDEFINED, (void*)&init_fct);
|
||||||
if (init_fct == NULL) {
|
if (init_fct == NULL) {
|
||||||
@ -1390,11 +1403,9 @@ dln_load(file)
|
|||||||
if(rld_lookup(NULL, buf, &init_address) == 0) {
|
if(rld_lookup(NULL, buf, &init_address) == 0) {
|
||||||
rb_loaderror("Failed to lookup Init function %.200s", file);
|
rb_loaderror("Failed to lookup Init function %.200s", file);
|
||||||
}
|
}
|
||||||
free(buf);
|
|
||||||
|
|
||||||
/* Cannot call *init_address directory, so copy this value to
|
/* Cannot call *init_address directory, so copy this value to
|
||||||
funtion pointer */
|
funtion pointer */
|
||||||
|
|
||||||
init_fct = (void(*)())init_address;
|
init_fct = (void(*)())init_address;
|
||||||
(*init_fct)();
|
(*init_fct)();
|
||||||
return (void*)init_address;
|
return (void*)init_address;
|
||||||
@ -1425,7 +1436,6 @@ dln_load(file)
|
|||||||
|
|
||||||
/* NSLookupAndBindSymbol require function name with "_" !! */
|
/* NSLookupAndBindSymbol require function name with "_" !! */
|
||||||
init_fct = NSAddressOfSymbol(NSLookupAndBindSymbol(buf));
|
init_fct = NSAddressOfSymbol(NSLookupAndBindSymbol(buf));
|
||||||
free(buf);
|
|
||||||
(*init_fct)();
|
(*init_fct)();
|
||||||
|
|
||||||
return (void*)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)) {
|
if ((B_BAD_IMAGE_ID == err_stat) || (B_BAD_INDEX == err_stat)) {
|
||||||
unload_add_on(img_id);
|
unload_add_on(img_id);
|
||||||
free(buf);
|
|
||||||
rb_loaderror("Failed to lookup Init function %.200s", file);
|
rb_loaderror("Failed to lookup Init function %.200s", file);
|
||||||
}
|
}
|
||||||
else if (B_NO_ERROR != err_stat) {
|
else if (B_NO_ERROR != err_stat) {
|
||||||
char errmsg[] = "Internal of BeOS version. %.200s (symbol_name = %s)";
|
char errmsg[] = "Internal of BeOS version. %.200s (symbol_name = %s)";
|
||||||
unload_add_on(img_id);
|
unload_add_on(img_id);
|
||||||
free(buf);
|
|
||||||
rb_loaderror(errmsg, strerror(err_stat), buf);
|
rb_loaderror(errmsg, strerror(err_stat), buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
|
||||||
/* call module initialize function. */
|
/* call module initialize function. */
|
||||||
(*init_fct)();
|
(*init_fct)();
|
||||||
return (void*)img_id;
|
return (void*)img_id;
|
||||||
@ -1521,7 +1528,6 @@ dln_load(file)
|
|||||||
/* Locate the address of the correct init function */
|
/* Locate the address of the correct init function */
|
||||||
c2pstr(buf);
|
c2pstr(buf);
|
||||||
err = FindSymbol(connID, buf, &symAddr, &class);
|
err = FindSymbol(connID, buf, &symAddr, &class);
|
||||||
free(buf);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
rb_loaderror("Unresolved symbols - %s" , file);
|
rb_loaderror("Unresolved symbols - %s" , file);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user