]> Devoid-pointer.net GitWeb - libHPCS.git/commitdiff
Fix memory leak in read_string_at_offset()
authorMichal Malý <madcatxster@devoid-pointer.net>
Sun, 29 Mar 2015 13:19:31 +0000 (15:19 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Sun, 29 Mar 2015 13:19:31 +0000 (15:19 +0200)
libhpcs.c

index c6d9e8dc76ddc59b225352ace048c396b65a1667..3f9eef515729eb98cc7ce4a5ffdd83a41d2fc407 100644 (file)
--- a/libhpcs.c
+++ b/libhpcs.c
@@ -773,6 +773,7 @@ static enum HPCS_ParseCode read_string_at_offset(FILE* datafile, const HPCS_offs
        char* string;
        uint8_t str_length;
        size_t r;
+       enum HPCS_ParseCode ret;
 
        fseek(datafile, offset, SEEK_SET);
        if (feof(datafile))
@@ -801,11 +802,13 @@ static enum HPCS_ParseCode read_string_at_offset(FILE* datafile, const HPCS_offs
 
 #ifdef _WIN32
        /* String is stored as native Windows WCHAR */
-       return __win32_wchar_to_utf8(result, string);
+       ret = __win32_wchar_to_utf8(result, string);
 #else
        /* Explicitly convert from UTF-16LE (internal WCHAR representation) */
-       return __unix_wchar_to_utf8(result, string, str_length * SEGMENT_SIZE);
+       ret = __unix_wchar_to_utf8(result, string, str_length * SEGMENT_SIZE);
 #endif
+       free(string);
+       return ret;
 }
 
 /** Platform-specific functions */