Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 6a6c555

Browse files
[[ Bug 14413 ]] Releasing the string created by the engine was causing a crash on Windows.
Changed ConvertCStringFromNativeToUTF8 to return a engine-free'd string.
1 parent c54444c commit 6a6c555

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

engine/src/externalv0.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,8 @@ static char *convert_from_native_to_utf8(const char *arg1, const char *arg2,
17371737
}
17381738

17391739
*retval = xresSucc;
1740+
// Return a string owned by the engine, to avoid the release issue
1741+
MCExternalAddAllocatedString(MCexternalallocpool, t_utf8_string);
17401742
return t_utf8_string;
17411743
}
17421744

@@ -1755,6 +1757,8 @@ static char *convert_to_native_from_utf8(const char *arg1, const char *arg2,
17551757
}
17561758

17571759
*retval = xresSucc;
1760+
// Return a string owned by the engine, to avoid the release issue
1761+
MCExternalAddAllocatedString(MCexternalallocpool, t_native_string);
17581762
return t_native_string;
17591763
}
17601764

libexternal/include/revolution/external.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,9 @@ extern Bool SecurityCanAccessLibraryUTF8(const char *p_library);
514514

515515

516516
// SN-2015-03-12: [[ Bug 14413 ]] Added UTF-8 <-> native string conversion
517-
extern char *ConvertCStringFromNativeToUTF8(const char *p_native, int *r_success);
518-
extern char *ConvertCStringToNativeFromUTF8(const char *p_utf8, int *r_success);
517+
// The string returned are owned by the engine, and must not be free'd
518+
extern const char *ConvertCStringFromNativeToUTF8(const char *p_native, int *r_success);
519+
extern const char *ConvertCStringToNativeFromUTF8(const char *p_utf8, int *r_success);
519520

520521
#ifdef __cplusplus
521522
};

libexternal/src/external.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ void ResolveSymbolInModule(void *p_handle, const char *p_symbol, void **r_resolv
911911
////////////////////////////////////////////////////////////////////////////////
912912
// V4: UTF-8 <-> native string conversion
913913

914-
char *ConvertCStringFromNativeToUTF8(const char *p_native, int *r_success)
914+
const char *ConvertCStringFromNativeToUTF8(const char *p_native, int *r_success)
915915
{
916916
char *t_result;
917917

@@ -926,7 +926,7 @@ char *ConvertCStringFromNativeToUTF8(const char *p_native, int *r_success)
926926
return t_result;
927927
}
928928

929-
char *ConvertCStringToNativeFromUTF8(const char *p_utf8, int *r_success)
929+
const char *ConvertCStringToNativeFromUTF8(const char *p_utf8, int *r_success)
930930
{
931931
char *t_result;
932932

revzip/src/revzip.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,19 +1279,19 @@ void revZipEnumerateItems(char *p_arguments[], int p_argument_count, char **r_re
12791279
}
12801280
else
12811281
{
1282-
char *t_converted_name;
1283-
int t_success;
1284-
12851282
// SN-2015-03-10: [[ Bug 14413 ]] We convert the string to UTF-8
12861283
// in case it was natively encoded, as revZipEnumerateItems is
12871284
// meant to return a UTF-8 encoded string.
1285+
const char *t_converted_name;
1286+
int t_success;
1287+
12881288
if (t_stat.bitflags && ZIP_UTF8_FLAG)
12891289
{
12901290
t_success = EXTERNAL_SUCCESS;
1291-
t_converted_name = strdup(t_stat.name);
1291+
t_converted_name = t_stat.name;
12921292
}
12931293
else
1294-
t_converted_name = ConvertCStringFromNativeToUTF8(t_stat.name, &t_success);
1294+
t_converted_name = ConvertCStringFromNativeToUTF8(t_stat.name, &t_success);
12951295

12961296
if (t_success == EXTERNAL_SUCCESS)
12971297
{
@@ -1304,9 +1304,6 @@ void revZipEnumerateItems(char *p_arguments[], int p_argument_count, char **r_re
13041304
t_error = True;
13051305
break;
13061306
}
1307-
1308-
// Free the allocated memory.
1309-
free(t_converted_name);
13101307
}
13111308
}
13121309

0 commit comments

Comments
 (0)