fix memory-management bugs in rktio on Windows
This commit is contained in:
parent
a15b16cfd9
commit
58dea081c6
|
@ -344,31 +344,31 @@ char *rktio_system_language_country(rktio_t *rktio)
|
||||||
/* Windows */
|
/* Windows */
|
||||||
LCID l;
|
LCID l;
|
||||||
int llen, clen;
|
int llen, clen;
|
||||||
char *lang, *country, *s;
|
wchar_t *lang, *country, *s;
|
||||||
l = GetUserDefaultLCID();
|
l = GetUserDefaultLCID();
|
||||||
|
|
||||||
llen = GetLocaleInfo(l, LOCALE_SENGLANGUAGE, NULL, 0);
|
llen = GetLocaleInfoW(l, LOCALE_SENGLANGUAGE, NULL, 0);
|
||||||
lang = malloc(llen);
|
lang = malloc(llen * sizeof(wchar_t));
|
||||||
GetLocaleInfo(l, LOCALE_SENGLANGUAGE, lang, llen);
|
GetLocaleInfo(l, LOCALE_SENGLANGUAGE, lang, llen);
|
||||||
if (llen)
|
if (llen)
|
||||||
llen -= 1; /* drop nul terminator */
|
llen -= 1; /* drop nul terminator */
|
||||||
|
|
||||||
clen = GetLocaleInfo(l, LOCALE_SENGCOUNTRY, NULL, 0);
|
clen = GetLocaleInfoW(l, LOCALE_SENGCOUNTRY, NULL, 0);
|
||||||
country = malloc(clen);
|
country = malloc(clen * sizeof(wchar_t));
|
||||||
GetLocaleInfo(l, LOCALE_SENGCOUNTRY, country, clen);
|
GetLocaleInfoW(l, LOCALE_SENGCOUNTRY, country, clen);
|
||||||
if (clen)
|
if (clen)
|
||||||
clen -= 1; /* drop nul terminator */
|
clen -= 1; /* drop nul terminator */
|
||||||
|
|
||||||
s = malloc(clen + llen + 2);
|
s = malloc((clen + llen + 2) * sizeof(wchar_t));
|
||||||
memcpy(s, lang, llen);
|
memcpy(s, lang, llen * sizeof(wchar_t));
|
||||||
memcpy(s + 1 + llen, country, clen);
|
memcpy(s + 1 + llen, country, clen * sizeof(wchar_t));
|
||||||
s[llen] = '_';
|
s[llen] = '_';
|
||||||
s[clen + llen + 1] = 0;
|
s[clen + llen + 1] = 0;
|
||||||
|
|
||||||
free(lang);
|
free(lang);
|
||||||
free(country);
|
free(country);
|
||||||
|
|
||||||
return s;
|
return NARROW_PATH_copy_then_free(s);
|
||||||
#else
|
#else
|
||||||
/* Unix */
|
/* Unix */
|
||||||
char *s;
|
char *s;
|
||||||
|
|
|
@ -365,7 +365,7 @@ static int UNC_stat(rktio_t *rktio, const char *dirname, int *flags, int *isdir,
|
||||||
|
|
||||||
len = strlen(dirname);
|
len = strlen(dirname);
|
||||||
|
|
||||||
copy = malloc(len+1);
|
copy = malloc(len+3); /* leave room to add `\.` */
|
||||||
memcpy(copy, dirname, len+1);
|
memcpy(copy, dirname, len+1);
|
||||||
|
|
||||||
if (!rktio->windows_nt_or_later
|
if (!rktio->windows_nt_or_later
|
||||||
|
|
Loading…
Reference in New Issue
Block a user