tfussell / xlnt

:bar_chart: Cross-platform user-friendly xlsx library for C++11+
Other
1.47k stars 409 forks source link

a bug about memory leak in MFC #744

Open weidoom opened 2 months ago

weidoom commented 2 months ago

Hi I use xlnt in visual studio 2022 ,install it from vcpkg. I create a console app with default template ,and then call xlnt , it works fine. but i create a MFC console application with default template, even if only defined a workbook object,there will be a lot of memory leak. like this: int main() { xlnt::workbook wb; return 0; } when I create a windows desktop app, xlnt works fine! but if create a MFC windows desktop app, there will be a lot of memory leak.

flaviu22 commented 2 months ago

"MFC console application" I don't know how you did that, a MFC app is a Windows application, not console, can you put here your steps to reproduce this issue? And you are sure if those memory leaks are from xlnt, or MFC app itself?

weidoom commented 2 months ago

"MFC console application " mean Create a console application with MFC headers; the step is: In Visual studio 2022

  1. Create a new project
  2. select" Windows Desktop Wizard" 3.Application type select "Console Application(.exe)" 4.Select "MFC headers" like this: MFC

I'm guessing it's because xlnt and mfc are a little incompatible. because create a console application without MFC header ,it work fine ,like this; NoMemoryLeakNoMFC If create a console application with MFC header, it cause a lot of memory leak,like this: MemoryLeak If I comment xlnt , there is no any memory leak,like this: NoMemoryLeak

if i use xlnt in console application with MFC header, I had to modify the numeric.hpp header file, otherwise it wouldn't compile successfully. including the max and min functions。add a bracket.

constexpr typename std::common_type<NumberL, NumberR>::type max(NumberL lval, NumberR rval) { return (lval < rval) ? rval : lval; } ---> template <typename NumberL, typename NumberR> constexpr typename std::common_type<NumberL, NumberR>::type (max)(NumberL lval, NumberR rval) { return (lval < rval) ? rval : lval; }

template <typename NumberL, typename NumberR> constexpr typename std::common_type<NumberL, NumberR>::type min(NumberL lval, NumberR rval) { return (lval < rval) ? lval : rval; } --》 template <typename NumberL, typename NumberR> constexpr typename std::common_type<NumberL, NumberR>::type (min)(NumberL lval, NumberR rval) { return (lval < rval) ? lval : rval; }

weidoom commented 2 months ago

In addition I did the following testcase: I created a standard DLL that exports a function ,for example , void Test();, in the function I called xlnt , it works fine in a console application, but if I call this DLL in an MFC console application it causes a lot of memory leak.

weidoom commented 2 months ago

I think this bug is not focused on MFC console application. In VS 2022,if I create any windows desktop application without mfc and call xlnt, it works fine, if create any windows desktop application with MFC, there will cause memory leak!