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:
parent
03bd7005bb
commit
f76fcb4eb4
2 changed files with 5 additions and 4 deletions
|
|
@ -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 *);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue