Memory leak fix handling const std::string & inputs, reported by Will Nolan.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12009 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2010-05-05 05:01:22 +00:00
commit f76fcb4eb4
2 changed files with 5 additions and 4 deletions

View file

@ -122,7 +122,7 @@ SWIGINTERN int
SWIG_AsCharPtrAndSize(SEXP obj, char** cptr, size_t* psize, int *alloc)
{
if (cptr && Rf_isString(obj)) {
const char *cstr = CHAR(STRING_ELT(obj, 0));
char *cstr = %const_cast(CHAR(STRING_ELT(obj, 0)), char *);
int len = strlen(cstr);
if (alloc) {
@ -130,9 +130,7 @@ SWIG_AsCharPtrAndSize(SEXP obj, char** cptr, size_t* psize, int *alloc)
*cptr = %new_copy_array(cstr, len + 1, char);
*alloc = SWIG_NEWOBJ;
} else {
*cptr = %reinterpret_cast(malloc(len + 1), char *);
*cptr = strcpy(*cptr, cstr);
*alloc = SWIG_OLDOBJ;
*cptr = cstr;
}
} else {
*cptr = %reinterpret_cast(malloc(len + 1), char *);