Skip to content

Commit f26de0c

Browse files
authored
Fix #14941: FN memleak with _create_locale (#8758)
1 parent 6d7e1da commit f26de0c

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

cfg/windows.cfg

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,11 @@
13311331
<alloc init="true" arg="11">AllocateAndInitializeSid</alloc>
13321332
<dealloc>FreeSid</dealloc>
13331333
</memory>
1334+
<memory>
1335+
<alloc init="true">_create_locale</alloc>
1336+
<alloc init="true">_wcreate_locale</alloc>
1337+
<dealloc>_free_locale</dealloc>
1338+
</memory>
13341339
<!--SIZE_T RtlCompareMemory(
13351340
_In_ const VOID *Source1,
13361341
_In_ const VOID *Source2,
@@ -5591,6 +5596,38 @@ HFONT CreateFont(
55915596
<not-uninit/>
55925597
</arg>
55935598
</function>
5599+
<!--_locale_t _create_locale(int category, const char *locale);
5600+
_locale_t _wcreate_locale(int category, const wchar_t *locale);
5601+
void _free_locale(_locale_t locale);-->
5602+
<function name="_create_locale">
5603+
<returnValue type="_locale_t"/>
5604+
<noreturn>false</noreturn>
5605+
<use-retval/>
5606+
<arg nr="1" direction="in">
5607+
<not-uninit/>
5608+
</arg>
5609+
<arg nr="2" direction="in">
5610+
<not-uninit/>
5611+
</arg>
5612+
</function>
5613+
<function name="_wcreate_locale">
5614+
<returnValue type="_locale_t"/>
5615+
<noreturn>false</noreturn>
5616+
<use-retval/>
5617+
<arg nr="1" direction="in">
5618+
<not-uninit/>
5619+
</arg>
5620+
<arg nr="2" direction="in">
5621+
<not-uninit/>
5622+
</arg>
5623+
</function>
5624+
<function name="_free_locale">
5625+
<noreturn>false</noreturn>
5626+
<returnValue type="void"/>
5627+
<arg nr="1">
5628+
<not-uninit/>
5629+
</arg>
5630+
</function>
55945631
<!--char * strlwr(_Inout_z_ char * _Str);-->
55955632
<function name="strlwr">
55965633
<returnValue type="char *">arg1</returnValue>

test/cfg/windows.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <wchar.h>
2424
#include <atlstr.h>
2525
#include <string>
26+
#include <locale.h>
2627

2728
bool UpdateTraceACalled(TRACEHANDLE traceHandle, LPCSTR loggerName, EVENT_TRACE_PROPERTIES* pProperties)
2829
{
@@ -615,6 +616,27 @@ void memleak_malloca()
615616
// cppcheck-suppress memleak
616617
}
617618

619+
void memleak_create_locale()
620+
{
621+
// cppcheck-suppress-begin valueFlowBailoutIncompleteVar
622+
_locale_t locale = _create_locale(LC_ALL, "C");
623+
_locale_t wlocale = _wcreate_locale(LC_ALL, L"C");
624+
(void) locale;
625+
(void) wlocale;
626+
// cppcheck-suppress-end valueFlowBailoutIncompleteVar
627+
// cppcheck-suppress memleak
628+
}
629+
630+
void no_memleak_create_locale()
631+
{
632+
// cppcheck-suppress-begin valueFlowBailoutIncompleteVar
633+
_locale_t locale = _create_locale(LC_ALL, "C");
634+
_locale_t wlocale = _wcreate_locale(LC_ALL, L"C");
635+
_free_locale(locale);
636+
_free_locale(wlocale);
637+
// cppcheck-suppress-end valueFlowBailoutIncompleteVar
638+
}
639+
618640
void memleak_AllocateAndInitializeSid()
619641
{
620642
PSID pEveryoneSID = NULL;

0 commit comments

Comments
 (0)