alloc_string does a copy (need to clean up some memory)

This commit is contained in:
Joshua Granick
2016-03-14 10:11:37 -07:00
parent 0579d97b9e
commit 75bb6905af

View File

@@ -247,7 +247,13 @@ namespace lime {
if (Clipboard::HasText ()) {
return alloc_string (Clipboard::GetText ());
const char* text = Clipboard::GetText ();
value _text = alloc_string (text);
// TODO: Should we free for all backends? (SDL requires it)
free ((char*)text);
return _text;
} else {
@@ -277,7 +283,18 @@ namespace lime {
#ifdef LIME_NFD
const char* path = FileDialog::OpenDirectory (filter.__s, defaultPath.__s);
return path ? alloc_string (path) : alloc_null ();
if (path) {
value _path = alloc_string (path);
free ((char*) path);
return _path;
} else {
return alloc_null ();
}
#endif
return 0;
@@ -288,7 +305,18 @@ namespace lime {
#ifdef LIME_NFD
const char* path = FileDialog::OpenFile (filter.__s, defaultPath.__s);
return path ? alloc_string (path) : alloc_null ();
if (path) {
value _path = alloc_string (path);
free ((char*) path);
return _path;
} else {
return alloc_null ();
}
#endif
return 0;
@@ -307,6 +335,7 @@ namespace lime {
for (int i = 0; i < files.size (); i++) {
val_array_set_i (result, i, alloc_string (files[i]));
free ((char*)files[i]);
}
#else
@@ -322,7 +351,18 @@ namespace lime {
#ifdef LIME_NFD
const char* path = FileDialog::SaveFile (filter.__s, defaultPath.__s);
return path ? alloc_string (path) : alloc_null ();
if (path) {
value _path = alloc_string (path);
free ((char*) path);
return _path;
} else {
return alloc_null ();
}
#endif
return 0;
@@ -1158,13 +1198,17 @@ namespace lime {
const char* path = System::GetDirectory ((SystemDirectory)type, company.__s, title.__s);
if (path) {
value dirPath = alloc_string(path);
free((char *)dirPath);
return dirPath;
} else {
return alloc_null();
}
if (path) {
value _path = alloc_string (path);
free ((char*) path);
return _path;
} else {
return alloc_null ();
}
}
@@ -1449,7 +1493,18 @@ namespace lime {
Window* targetWindow = (Window*)val_data (window);
const char* result = targetWindow->SetTitle (title.__s);
return result ? alloc_string (result) : alloc_null ();
if (result) {
value _result = alloc_string (result);
free ((char*) result);
return _result;
} else {
return alloc_null ();
}
}