Fix minor memory leak (Android)
authorCraig Robbins <kde.psych@gmail.com>
Fri, 27 Feb 2015 03:40:27 +0000 (13:40 +1000)
committerCraig Robbins <kde.psych@gmail.com>
Fri, 27 Feb 2015 03:40:27 +0000 (13:40 +1000)
src/util/string.cpp

index 8861981b210978604e07018634d5c8a8c1a7a690..9e2123d590dabe74719b238bfb02235786b110eb 100644 (file)
@@ -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!