Remove redundant NULL checks before free()/delete (#2184)
Remove redundant NULL checks before free()/delete The ISO C and C++ standards guarantee that it's safe to call these on a NULL pointer, so it's not necessary for the calling code to also check. Fixes https://sourceforge.net/p/swig/feature-requests/70/
This commit is contained in:
parent
5a10e10399
commit
7ec2f89fe2
17 changed files with 44 additions and 51 deletions
|
|
@ -1470,14 +1470,14 @@ SWIG generates the following code:
|
|||
<pre>
|
||||
/* C mode */
|
||||
void foo_set(char *value) {
|
||||
if (foo) free(foo);
|
||||
free(foo);
|
||||
foo = (char *) malloc(strlen(value)+1);
|
||||
strcpy(foo, value);
|
||||
}
|
||||
|
||||
/* C++ mode. When -c++ option is used */
|
||||
void foo_set(char *value) {
|
||||
if (foo) delete [] foo;
|
||||
delete [] foo;
|
||||
foo = new char[strlen(value)+1];
|
||||
strcpy(foo, value);
|
||||
}
|
||||
|
|
@ -2635,8 +2635,7 @@ char *Foo_name_get(Foo *obj) {
|
|||
}
|
||||
|
||||
char *Foo_name_set(Foo *obj, char *c) {
|
||||
if (obj->name)
|
||||
free(obj->name);
|
||||
free(obj->name);
|
||||
obj->name = (char *) malloc(strlen(c)+1);
|
||||
strcpy(obj->name, c);
|
||||
return obj->name;
|
||||
|
|
|
|||
|
|
@ -2811,9 +2811,7 @@ used as a <tt>char **</tt> object.
|
|||
|
||||
// This gives SWIG some cleanup code that will get called after the function call
|
||||
%typemap(freearg) char ** {
|
||||
if ($1) {
|
||||
free($1);
|
||||
}
|
||||
free($1);
|
||||
}
|
||||
|
||||
// Now a test functions
|
||||
|
|
|
|||
|
|
@ -3103,7 +3103,7 @@ as shown. To work with heap allocated data, the following technique can be use
|
|||
}
|
||||
}
|
||||
%typemap(freearg) float value[ANY] {
|
||||
if ($1) free($1);
|
||||
free($1);
|
||||
}
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -3556,7 +3556,7 @@ maps perform the conversion described for the above example:
|
|||
}
|
||||
|
||||
%typemap(freearg) (int argc, char *argv[]) {
|
||||
if ($2) free($2);
|
||||
free($2);
|
||||
}
|
||||
|
||||
/* Required for C++ method overloading */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue