Resource leak fixes (or hiding them from Coverity static analysis tool by using String instead of char *)

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13886 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2012-11-14 22:16:54 +00:00
commit 46d2486115
12 changed files with 62 additions and 63 deletions

View file

@ -48,7 +48,7 @@ static File *f_cxx_wrapper = 0;
static String *module_name = 0; static String *module_name = 0;
static String *swig_package = 0; static String *swig_package = 0;
const char *identifier_converter = "identifier-convert-null"; static String *identifier_converter = NewString("identifier-convert-null");
static bool CWrap = true; // generate wrapper file for C code by default. most correct. static bool CWrap = true; // generate wrapper file for C code by default. most correct.
static bool Generate_Wrapper = false; static bool Generate_Wrapper = false;
@ -1605,14 +1605,15 @@ void ALLEGROCL::main(int argc, char *argv[]) {
/* check for built-ins */ /* check for built-ins */
if (!strcmp(conv, "lispify")) { if (!strcmp(conv, "lispify")) {
identifier_converter = "identifier-convert-lispify"; Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-lispify");
} else if (!strcmp(conv, "null")) { } else if (!strcmp(conv, "null")) {
identifier_converter = "identifier-convert-null"; Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-null");
} else { } else {
/* Must be user defined */ /* Must be user defined */
char *idconv = new char[strlen(conv) + 1]; Delete(identifier_converter);
strcpy(idconv, conv); identifier_converter = NewString(conv);
identifier_converter = idconv;
} }
} else if (!strcmp(argv[i], "-cwrap")) { } else if (!strcmp(argv[i], "-cwrap")) {
CWrap = true; CWrap = true;

View file

@ -792,8 +792,10 @@ public:
if (Getattr(n, "sym:overloaded")) { if (Getattr(n, "sym:overloaded")) {
// Emit warnings for the few cases that can't be overloaded in C# and give up on generating wrapper // Emit warnings for the few cases that can't be overloaded in C# and give up on generating wrapper
Swig_overload_check(n); Swig_overload_check(n);
if (Getattr(n, "overload:ignore")) if (Getattr(n, "overload:ignore")) {
DelWrapper(f);
return SWIG_OK; return SWIG_OK;
}
} }
Printv(imclass_class_code, "\n [DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL); Printv(imclass_class_code, "\n [DllImport(\"", dllimport, "\", EntryPoint=\"", wname, "\")]\n", NIL);

View file

@ -1579,8 +1579,10 @@ public:
if (Getattr(n, "sym:overloaded")) { if (Getattr(n, "sym:overloaded")) {
// Emit warnings for the few cases that can't be overloaded in D and give up on generating wrapper // Emit warnings for the few cases that can't be overloaded in D and give up on generating wrapper
Swig_overload_check(n); Swig_overload_check(n);
if (Getattr(n, "overload:ignore")) if (Getattr(n, "overload:ignore")) {
DelWrapper(f);
return SWIG_OK; return SWIG_OK;
}
} }
// Collect the parameter list for the intermediary D module declaration of // Collect the parameter list for the intermediary D module declaration of

View file

@ -3640,6 +3640,7 @@ private:
Delete(upcall_name); Delete(upcall_name);
Delete(callback_wname); Delete(callback_wname);
Delete(go_name); Delete(go_name);
DelWrapper(w);
return SWIG_OK; return SWIG_OK;
} }

View file

@ -59,9 +59,9 @@ static File *f_wrappers = 0;
static File *f_init = 0; static File *f_init = 0;
static char *prefix = (char *) "gswig_"; static String *prefix = NewString("gswig_");
static char *module = 0; static char *module = 0;
static char *package = 0; static String *package = 0;
static enum { static enum {
GUILE_LSTYLE_SIMPLE, // call `SWIG_init()' GUILE_LSTYLE_SIMPLE, // call `SWIG_init()'
GUILE_LSTYLE_PASSIVE, // passive linking (no module code) GUILE_LSTYLE_PASSIVE, // passive linking (no module code)
@ -127,7 +127,7 @@ public:
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
virtual void main(int argc, char *argv[]) { virtual void main(int argc, char *argv[]) {
int i, orig_len; int i;
SWIG_library_directory("guile"); SWIG_library_directory("guile");
SWIG_typemap_lang("guile"); SWIG_typemap_lang("guile");
@ -140,8 +140,7 @@ public:
SWIG_exit(EXIT_SUCCESS); SWIG_exit(EXIT_SUCCESS);
} else if (strcmp(argv[i], "-prefix") == 0) { } else if (strcmp(argv[i], "-prefix") == 0) {
if (argv[i + 1]) { if (argv[i + 1]) {
prefix = new char[strlen(argv[i + 1]) + 2]; prefix = NewString(argv[i + 1]);
strcpy(prefix, argv[i + 1]);
Swig_mark_arg(i); Swig_mark_arg(i);
Swig_mark_arg(i + 1); Swig_mark_arg(i + 1);
i++; i++;
@ -150,8 +149,7 @@ public:
} }
} else if (strcmp(argv[i], "-package") == 0) { } else if (strcmp(argv[i], "-package") == 0) {
if (argv[i + 1]) { if (argv[i + 1]) {
package = new char[strlen(argv[i + 1]) + 2]; package = NewString(argv[i + 1]);
strcpy(package, argv[i + 1]);
Swig_mark_arg(i); Swig_mark_arg(i);
Swig_mark_arg(i + 1); Swig_mark_arg(i + 1);
i++; i++;
@ -278,12 +276,12 @@ public:
// should use Swig_warning() ? // should use Swig_warning() ?
Printf(stderr, "guile: Warning: -exportprimitive only makes sense with passive linkage without a scmstub.\n"); Printf(stderr, "guile: Warning: -exportprimitive only makes sense with passive linkage without a scmstub.\n");
} }
// Make sure `prefix' ends in an underscore
orig_len = strlen(prefix); // Make sure `prefix' ends in an underscore
if (prefix[orig_len - 1] != '_') { if (prefix) {
prefix[1 + orig_len] = 0; const char *px = Char(prefix);
prefix[orig_len] = '_'; if (px[Len(prefix)] != '_')
Printf(prefix, "_");
} }
/* Add a symbol for this module */ /* Add a symbol for this module */

View file

@ -876,8 +876,10 @@ public:
if (Getattr(n, "sym:overloaded")) { if (Getattr(n, "sym:overloaded")) {
// Emit warnings for the few cases that can't be overloaded in Java and give up on generating wrapper // Emit warnings for the few cases that can't be overloaded in Java and give up on generating wrapper
Swig_overload_check(n); Swig_overload_check(n);
if (Getattr(n, "overload:ignore")) if (Getattr(n, "overload:ignore")) {
DelWrapper(f);
return SWIG_OK; return SWIG_OK;
}
} }
Printf(imclass_class_code, " public final static native %s %s(", im_return_type, overloaded_name); Printf(imclass_class_code, " public final static native %s %s(", im_return_type, overloaded_name);

View file

@ -33,12 +33,10 @@ static String *convert_proto_tab = 0;
static String *struct_name = 0; static String *struct_name = 0;
static String *mangled_struct_name = 0; static String *mangled_struct_name = 0;
static char *prefix = 0; static String *prefix = 0;
static bool declaremodule = false; static bool declaremodule = false;
static bool noinit = false; static bool noinit = false;
//DLOPEN PATCH static String *load_libraries = NULL;
static char *load_libraries = NULL;
//DLOPEN PATCH
static String *module = 0; static String *module = 0;
static char *mzscheme_path = (char *) "mzscheme"; static char *mzscheme_path = (char *) "mzscheme";
static String *init_func_def = 0; static String *init_func_def = 0;
@ -75,8 +73,7 @@ public:
SWIG_exit(0); SWIG_exit(0);
} else if (strcmp(argv[i], "-prefix") == 0) { } else if (strcmp(argv[i], "-prefix") == 0) {
if (argv[i + 1]) { if (argv[i + 1]) {
prefix = new char[strlen(argv[i + 1]) + 2]; prefix = NewString(argv[i + 1]);
strcpy(prefix, argv[i + 1]);
Swig_mark_arg(i); Swig_mark_arg(i);
Swig_mark_arg(i + 1); Swig_mark_arg(i + 1);
i++; i++;
@ -90,26 +87,27 @@ public:
noinit = true; noinit = true;
Swig_mark_arg(i); Swig_mark_arg(i);
} }
// DLOPEN PATCH
else if (strcmp(argv[i], "-dynamic-load") == 0) { else if (strcmp(argv[i], "-dynamic-load") == 0) {
load_libraries = new char[strlen(argv[i + 1]) + 2]; if (argv[i + 1]) {
strcpy(load_libraries, argv[i + 1]); Delete(load_libraries);
Swig_mark_arg(i++); load_libraries = NewString(argv[i + 1]);
Swig_mark_arg(i); Swig_mark_arg(i++);
Swig_mark_arg(i);
} else {
Swig_arg_error();
}
} }
// DLOPEN PATCH
} }
} }
// If a prefix has been specified make sure it ends in a '_' // If a prefix has been specified make sure it ends in a '_' (not actually used!)
if (prefix) { if (prefix) {
if (prefix[strlen(prefix)] != '_') { const char *px = Char(prefix);
prefix[strlen(prefix) + 1] = 0; if (px[Len(prefix)] != '_')
prefix[strlen(prefix)] = '_'; Printf(prefix, "_");
}
} else } else
prefix = (char *) "swig_"; prefix = NewString("swig_");
// Add a symbol for this module // Add a symbol for this module
@ -177,11 +175,9 @@ public:
Printf(f_init, "\treturn scheme_void;\n}\n"); Printf(f_init, "\treturn scheme_void;\n}\n");
Printf(f_init, "Scheme_Object *scheme_initialize(Scheme_Env *env) {\n"); Printf(f_init, "Scheme_Object *scheme_initialize(Scheme_Env *env) {\n");
// DLOPEN PATCH
if (load_libraries) { if (load_libraries) {
Printf(f_init, "mz_set_dlopen_libraries(\"%s\");\n", load_libraries); Printf(f_init, "mz_set_dlopen_libraries(\"%s\");\n", load_libraries);
} }
// DLOPEN PATCH
Printf(f_init, "\treturn scheme_reload(env);\n"); Printf(f_init, "\treturn scheme_reload(env);\n");
Printf(f_init, "}\n"); Printf(f_init, "}\n");
@ -244,14 +240,12 @@ public:
int numreq; int numreq;
String *overname = 0; String *overname = 0;
// PATCH DLOPEN
if (load_libraries) { if (load_libraries) {
ParmList *parms = Getattr(n, "parms"); ParmList *parms = Getattr(n, "parms");
SwigType *type = Getattr(n, "type"); SwigType *type = Getattr(n, "type");
String *name = NewString("caller"); String *name = NewString("caller");
Setattr(n, "wrap:action", Swig_cresult(type, Swig_cresult_name(), Swig_cfunction_call(name, parms))); Setattr(n, "wrap:action", Swig_cresult(type, Swig_cresult_name(), Swig_cfunction_call(name, parms)));
} }
// PATCH DLOPEN
// Make a wrapper name for this // Make a wrapper name for this
String *wname = Swig_name_wrapper(iname); String *wname = Swig_name_wrapper(iname);
@ -291,7 +285,6 @@ public:
numargs = emit_num_arguments(l); numargs = emit_num_arguments(l);
numreq = emit_num_required(l); numreq = emit_num_required(l);
// DLOPEN PATCH
/* Add the holder for the pointer to the function to be opened */ /* Add the holder for the pointer to the function to be opened */
if (load_libraries) { if (load_libraries) {
Wrapper_add_local(f, "_function_loaded", "static int _function_loaded=(1==0)"); Wrapper_add_local(f, "_function_loaded", "static int _function_loaded=(1==0)");
@ -302,19 +295,16 @@ public:
Wrapper_add_local(f, "caller", SwigType_lstr(d, func)); /*"(*caller)()")); */ Wrapper_add_local(f, "caller", SwigType_lstr(d, func)); /*"(*caller)()")); */
} }
} }
// DLOPEN PATCH
// adds local variables // adds local variables
Wrapper_add_local(f, "lenv", "int lenv = 1"); Wrapper_add_local(f, "lenv", "int lenv = 1");
Wrapper_add_local(f, "values", "Scheme_Object *values[MAXVALUES]"); Wrapper_add_local(f, "values", "Scheme_Object *values[MAXVALUES]");
// DLOPEN PATCH
if (load_libraries) { if (load_libraries) {
Printf(f->code, "if (!_function_loaded) { _the_function=mz_load_function(\"%s\");_function_loaded=(1==1); }\n", iname); Printf(f->code, "if (!_function_loaded) { _the_function=mz_load_function(\"%s\");_function_loaded=(1==1); }\n", iname);
Printf(f->code, "if (!_the_function) { scheme_signal_error(\"Cannot load C function '%s'\"); }\n", iname); Printf(f->code, "if (!_the_function) { scheme_signal_error(\"Cannot load C function '%s'\"); }\n", iname);
Printf(f->code, "caller=_the_function;\n"); Printf(f->code, "caller=_the_function;\n");
} }
// DLOPEN PATCH
// Now write code to extract the parameters (this is super ugly) // Now write code to extract the parameters (this is super ugly)

View file

@ -30,7 +30,7 @@ static int in_constructor = 0, in_destructor = 0, in_copyconst = 0;
static int const_enum = 0; static int const_enum = 0;
static int static_member_function = 0; static int static_member_function = 0;
static int generate_sizeof = 0; static int generate_sizeof = 0;
static char *prefix = 0; static String *prefix = 0;
static char *ocaml_path = (char *) "ocaml"; static char *ocaml_path = (char *) "ocaml";
static bool old_variable_names = false; static bool old_variable_names = false;
static String *classname = 0; static String *classname = 0;
@ -107,8 +107,7 @@ public:
SWIG_exit(0); SWIG_exit(0);
} else if (strcmp(argv[i], "-prefix") == 0) { } else if (strcmp(argv[i], "-prefix") == 0) {
if (argv[i + 1]) { if (argv[i + 1]) {
prefix = new char[strlen(argv[i + 1]) + 2]; prefix = NewString(argv[i + 1]);
strcpy(prefix, argv[i + 1]);
Swig_mark_arg(i); Swig_mark_arg(i);
Swig_mark_arg(i + 1); Swig_mark_arg(i + 1);
i++; i++;
@ -130,15 +129,14 @@ public:
} }
} }
// If a prefix has been specified make sure it ends in a '_' // If a prefix has been specified make sure it ends in a '_' (not actually used!)
if (prefix) { if (prefix) {
if (prefix[strlen(prefix)] != '_') { const char *px = Char(prefix);
prefix[strlen(prefix) + 1] = 0; if (px[Len(prefix)] != '_')
prefix[strlen(prefix)] = '_'; Printf(prefix, "_");
}
} else } else
prefix = (char *) "swig_"; prefix = NewString("swig_");
// Add a symbol for this module // Add a symbol for this module

View file

@ -524,7 +524,6 @@ public:
} }
virtual int functionWrapper(Node *n) { virtual int functionWrapper(Node *n) {
Wrapper *f = NewWrapper();
Parm *p; Parm *p;
String *tm; String *tm;
int j; int j;
@ -551,6 +550,7 @@ public:
if (!overloaded || last_overload) if (!overloaded || last_overload)
process_autodoc(n); process_autodoc(n);
Wrapper *f = NewWrapper();
Octave_begin_function(n, f->def, iname, overname, !overloaded); Octave_begin_function(n, f->def, iname, overname, !overloaded);
emit_parameter_variables(l, f); emit_parameter_variables(l, f);
@ -859,6 +859,8 @@ public:
Delete(getwname); Delete(getwname);
Delete(setwname); Delete(setwname);
DelWrapper(setf);
DelWrapper(getf);
return SWIG_OK; return SWIG_OK;
} }

View file

@ -2330,6 +2330,7 @@ done:
Printf(f->code, "}\n"); Printf(f->code, "}\n");
Wrapper_print(f, s_wrappers); Wrapper_print(f, s_wrappers);
DelWrapper(f);
return SWIG_OK; return SWIG_OK;
} }

View file

@ -726,6 +726,7 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
Delete(rtype); Delete(rtype);
Delete(rettype); Delete(rettype);
Delete(funcparams); Delete(funcparams);
DelWrapper(f);
return funName; return funName;
} }

View file

@ -47,7 +47,7 @@ static struct {
String **entries; String **entries;
} defined_foreign_types; } defined_foreign_types;
static const char *identifier_converter = "identifier-convert-null"; static String *identifier_converter = NewString("identifier-convert-null");
static int any_varargs(ParmList *pl) { static int any_varargs(ParmList *pl) {
Parm *p; Parm *p;
@ -221,14 +221,15 @@ void UFFI::main(int argc, char *argv[]) {
/* check for built-ins */ /* check for built-ins */
if (!strcmp(conv, "lispify")) { if (!strcmp(conv, "lispify")) {
identifier_converter = "identifier-convert-lispify"; Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-lispify");
} else if (!strcmp(conv, "null")) { } else if (!strcmp(conv, "null")) {
identifier_converter = "identifier-convert-null"; Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-null");
} else { } else {
/* Must be user defined */ /* Must be user defined */
char *idconv = new char[strlen(conv) + 1]; Delete(identifier_converter);
strcpy(idconv, conv); identifier_converter = NewString(conv);
identifier_converter = idconv;
} }
} }