aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorCraig Robbins <kde.psych@gmail.com>2015-02-27 13:40:27 +1000
committerCraig Robbins <kde.psych@gmail.com>2015-02-27 13:40:27 +1000
commit338e66af5f0a645e5d161ca83d048b27c3095165 (patch)
treefa601cd14060c59641ef9ca60918db4eaf13ff94 /src/util
parent14f7df980b5be20339ab637a96bdc08ac907abf2 (diff)
downloadminetest-338e66af5f0a645e5d161ca83d048b27c3095165.tar.gz
minetest-338e66af5f0a645e5d161ca83d048b27c3095165.tar.bz2
minetest-338e66af5f0a645e5d161ca83d048b27c3095165.zip
Fix minor memory leak (Android)
Diffstat (limited to 'src/util')
-rw-r--r--src/util/string.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/util/string.cpp b/src/util/string.cpp
index 8861981b2..9e2123d59 100644
--- a/src/util/string.cpp
+++ b/src/util/string.cpp
@@ -40,6 +40,7 @@ static bool parseHexColorString(const std::string &value, video::SColor &color);
static bool parseNamedColorString(const std::string &value, video::SColor &color);
#ifdef __ANDROID__
+
const wchar_t* wide_chars =
L" !\"#$%&'()*+,-./0123456789:;<=>?@"
L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`"
@@ -62,14 +63,18 @@ int wctomb(char *s, wchar_t wc)
int mbtowc(wchar_t *pwc, const char *s, size_t n)
{
+ if (s == NULL || *s == '\0')
+ return -1;
+
const wchar_t *tmp = narrow_to_wide_c(s);
+ bool success = tmp[0] != '\0';
- if (tmp[0] != '\0') {
+ if (success)
*pwc = tmp[0];
- return 1;
- } else {
- return -1;
- }
+
+ delete tmp;
+
+ return success ? 1 : -1;
}
// You must free the returned string!