Memory corruption error in Windows version

18 views
Skip to first unread message

Russell Wallace

unread,
Jan 30, 2021, 2:12:25 PMJan 30
to mpir-...@googlegroups.com
I'm running into a memory corruption error with the Windows version of MPIR, which shows up in the following minimal test case.

Microsoft (R) C/C++ Optimizing Compiler Version 19.25.28610.4 for x64

Compiled MPIR from the latest github checkout earlier this month with this script:

pushd \mpir\msvc\vs19
call msbuild.bat gc DLL x64 Debug
call msbuild.bat gc LIB x64 Release
popd
copy \mpir\dll\x64\Debug\mpir.dll

Using this source file as a test case:

#include <stdio.h>
#include <gmp.h>

int main(int argc, const char **argv) {
  mpz_t x;
  mpz_init_set_str(x,"123",10);
  mpz_out_str(stdout,10,x);
  putchar('\n');
  return 0;
}

Compiling like this:

cl /I\mpir /MTd a.cc \mpir\dll\x64\Debug\mpir.lib

And running the resulting program, produces correct output, but on exit shows a heap corruption, with an error message in a pop-up window that unknowingly does not allow copy paste, but it's in

C:\Program Files (x86)\Windows Kits\10\Source\10.0.18362.0\ucrt\heap\debug_heap.cpp

line 996, which is

            _ASSERTE(__acrt_first_block == header);

Gisle Vanem

unread,
Jan 31, 2021, 5:35:41 AMJan 31
to mpir-...@googlegroups.com
Russell Wallace wrote:

> And running the resulting program, produces correct output, but on exit shows a heap corruption, with an error message
> in a pop-up window that unknowingly does not allow copy paste, but it's in

I've no problem with your program. Only issue I see with
MSVC-2019 in debug-mode ('-MDd -RTC1 -RTCu' in CFLAGS and using mpir.dll),
is in speed.exe. When running:
speed -c -s 10(10)1000 mpn_preinv_divrem_1f.3333

gives this call-stack:
speed!failwithmessage(void * retaddr = 0x0006e5c7, int crttype = 1, int errnum = 4,
char * msg = 0x0053d5e8 "Stack area around _alloca memory reserved by
this function is corrupted.Address: 0x0053D780.Size: 220.Allocation number within this function:
1.Data: <a???")+0x1ec
speed!_RTC_AllocaFailure(void * retaddr = 0x0006e5c7, struct _RTC_ALLOCA_NODE * pn = 0x0053d760,
int num = 1)+0xd2
speed!_RTC_CheckStackVars2(void * frame = 0x0053d8e4, struct _RTC_framedesc *,
struct _RTC_ALLOCA_NODE * allocaList = 0x0053d760)+0xa6
speed!speed_mpn_preinv_divrem_1f(struct speed_params * s = 0x001206a0)+0x407
speed!speed_measure(<function> * fun = 0x0006e1c0, struct speed_params * s = 0x001206a0)+0xbf
speed!run_one(struct _iobuf * fp = 0x61fd5a78, struct speed_params * s = 0x001206a0,
long prev_size = 0x1e)+0x32c
speed!run_all(struct _iobuf * fp = 0x61fd5a78)+0x188
speed!main(int argc = 5, char ** argv = 0x00747750)+0xa6a
speed!invoke_main(void)+0x33
...

Increasing the stack with 'LDFLAGS += -stack:5000000'
does not help.

--
--gv




MPIR-speed.png
Reply all
Reply to author
Forward
0 new messages