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 ()) { 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 { } else {
@@ -277,7 +283,18 @@ namespace lime {
#ifdef LIME_NFD #ifdef LIME_NFD
const char* path = FileDialog::OpenDirectory (filter.__s, defaultPath.__s); 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 #endif
return 0; return 0;
@@ -288,7 +305,18 @@ namespace lime {
#ifdef LIME_NFD #ifdef LIME_NFD
const char* path = FileDialog::OpenFile (filter.__s, defaultPath.__s); 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 #endif
return 0; return 0;
@@ -307,6 +335,7 @@ namespace lime {
for (int i = 0; i < files.size (); i++) { for (int i = 0; i < files.size (); i++) {
val_array_set_i (result, i, alloc_string (files[i])); val_array_set_i (result, i, alloc_string (files[i]));
free ((char*)files[i]);
} }
#else #else
@@ -322,7 +351,18 @@ namespace lime {
#ifdef LIME_NFD #ifdef LIME_NFD
const char* path = FileDialog::SaveFile (filter.__s, defaultPath.__s); 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 #endif
return 0; return 0;
@@ -1159,11 +1199,15 @@ namespace lime {
const char* path = System::GetDirectory ((SystemDirectory)type, company.__s, title.__s); const char* path = System::GetDirectory ((SystemDirectory)type, company.__s, title.__s);
if (path) { if (path) {
value dirPath = alloc_string(path);
free((char *)dirPath); value _path = alloc_string (path);
return dirPath; free ((char*) path);
return _path;
} else { } else {
return alloc_null();
return alloc_null ();
} }
} }
@@ -1449,7 +1493,18 @@ namespace lime {
Window* targetWindow = (Window*)val_data (window); Window* targetWindow = (Window*)val_data (window);
const char* result = targetWindow->SetTitle (title.__s); 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 ();
}
} }