From: Michal Rokos Date: 2002-08-30T23:38:27+09:00 Subject: [MemLeak] in dln.c Hi, am I right? 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/08/30 14:35:07 @@ -647,7 +647,10 @@ 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)); @@ -1260,11 +1263,12 @@ dln_load(file) /* Load file */ if ((handle = LoadLibrary(winfile)) == NULL) { error = dln_strerror(); + free(buf); goto failed; } 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); /* FIXME: MEMLEAK for buf */ } free(buf); @@ -1300,6 +1304,7 @@ dln_load(file) /* Load file */ if ((handle = (void*)dlopen(file, RTLD_LAZY|RTLD_GLOBAL)) == NULL) { error = dln_strerror(); + free(buf); goto failed; } @@ -1328,6 +1333,7 @@ dln_load(file) lib = shl_load(file, flags, 0); if (lib == NULL) { extern int errno; + free(buf); rb_loaderror("%s - %s", strerror(errno), file); } shl_findsym(&lib, buf, TYPE_PROCEDURE, (void*)&init_fct); @@ -1349,6 +1355,8 @@ dln_load(file) { void (*init_fct)(); + free(buf); + init_fct = (void(*)())load((char*)file, 1, 0); if (init_fct == NULL) { aix_loaderror(file); @@ -1388,6 +1396,7 @@ dln_load(file) /* lookup the initial function */ if(rld_lookup(NULL, buf, &init_address) == 0) { + free(buf); rb_loaderror("Failed to lookup Init function %.200s", file); } free(buf); @@ -1412,6 +1421,7 @@ dln_load(file) dyld_result = NSCreateObjectFileImageFromFile(file, &obj_file); if (dyld_result != NSObjectFileImageSuccess) { + free(buf); rb_loaderror("Failed to load %.200s", file); } @@ -1420,6 +1430,7 @@ dln_load(file) /* lookup the initial function */ /*NSIsSymbolNameDefined require function name without "_" */ if(NSIsSymbolNameDefined(buf + 1)) { + free(buf); rb_loaderror("Failed to lookup Init function %.200s",file); } @@ -1443,6 +1454,7 @@ dln_load(file) /* load extention module */ img_id = load_add_on(file); if (img_id <= 0) { + free(buf); rb_loaderror("Failed to load %.200s", file); } @@ -1472,8 +1484,7 @@ dln_load(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); + rb_loaderror(errmsg, strerror(err_stat), buf); /* FIXME: MEM LEAK for buf */ } free(buf); @@ -1505,6 +1516,7 @@ dln_load(file) (void)FSMakeFSSpec(0, 0, fullpath, &libspec); err = ResolveAliasFile(&libspec, 1, &isfolder, &didsomething); if (err) { + free(buf); rb_loaderror("Unresolved Alias - %s", file); } @@ -1514,6 +1526,7 @@ dln_load(file) kLoadCFrag, &connID, &mainAddr, errMessage); if (err) { + free(buf); p2cstr(errMessage); rb_loaderror("%s - %s",errMessage , file); } @@ -1545,15 +1558,18 @@ dln_load(file) *p2 = '\0'; if ((handle = (void*)dlopen(fname, 0)) == NULL) { + free(buf); error = dln_strerror(); goto failed; } if ((init_fct = (void (*)())dlsym(handle, buf)) == NULL) { + free(buf); error = DLN_ERROR(); dlclose(handle); goto failed; } + free(buf); /* Call the init code */ (*init_fct)(); return handle; -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Michal Rokos Czech Technical University, Prague E-mail:m.rokos@sh.cvut.cz ICQ:36118339 Jabber:majkl@jabber.cz -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-