Csound Csound-dev Csound-tekno Search About

[Csnd-dev] Crashes (mrealloc?)

Date2017-10-20 20:44
FromSteven Yi
Subject[Csnd-dev] Crashes (mrealloc?)
Attachmentslive0.csd  
Hi All,

I've been chasing down a crash and it's been hard to diagnose.  Attached is an updated copy of of the live coding code I've been working. I have been re-evaluating live the following code:

gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)

modifying the arguments to fillarray() to changes the contents of the gkscale array.  I can modify and re-evaluate and get updated values (using csound as UDP server with --port=10000) but then it will eventually crash when I do an eval.


I've tried a few ways of debugging. I have been using MinGW-compiled csound primarily for regular work at this time.  This is built using RelWithDebInfo.  When I run csound from the commandline with "-odac live0.csd --port=10000" and send code from Vim to eval, I would eventually get a crash.  If I run the same csound under GDB, it does not crash.

Using Visual Studio compiled builds, I get different behavior.  With RelWithDebInfo build and running within VS, I get a crash and it traces to a failure in memalloc.c:mrealloc():

    /* allocate memory */
    p = realloc((void*) pp, ALLOC_BYTES(size));

Stack trace is as follows: 

  ntdll.dll!00007fff58c3771e() Unknown Non-user code. Cannot find or open the PDB file.
  ntdll.dll!00007fff58c3df0a() Unknown Non-user code. Cannot find or open the PDB file.
  ntdll.dll!00007fff58be4f22() Unknown Non-user code. Cannot find or open the PDB file.
  ntdll.dll!00007fff58bf6a8a() Unknown Non-user code. Cannot find or open the PDB file.
  ntdll.dll!00007fff58b6831a() Unknown Non-user code. Cannot find or open the PDB file.
  ucrtbase.dll!00007fff55071bf9() Unknown Non-user code. Cannot find or open the PDB file.
  csound64.dll!mrealloc(CSOUND_ * csound, void * oldp, unsigned __int64 size) Line 208 C Symbols loaded.
> csound64.dll!tabcopy(CSOUND_ * csound, TABCPY * p) Line 1445 C Symbols loaded.
  csound64.dll!init0(CSOUND_ * csound) Line 64 C Symbols loaded.
  csound64.dll!merge_state(CSOUND_ * csound, engine_state * engineState, type_table * typetable, opds * ids) Line 1452 C Symbols loaded.
  csound64.dll!message_dequeue(CSOUND_ * csound) Line 247 C Symbols loaded.
  csound64.dll!kperf_nodebug(CSOUND_ * csound) Line 1582 C Symbols loaded.
  csound64.dll!csoundPerform(CSOUND_ * csound) Line 2155 C Symbols loaded.
  csound.exe!main(int argc, char * * argv) Line 325 C Symbols loaded.
  [External Code] Annotated Frame

I seem to get this consistently if I use change size of the array to one size less, then one size bigger again. So the code I would evaluate is:

gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)
gkscale[] = fillarray(0, 2, 3, 5, 7, 8)
gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)

one line at a time. 

I tried using a Debug build of Visual Studio, but it crashes in realloc very early in the program:

  ntdll.dll!00007fff58b686c8() Unknown Non-user code. Cannot find or open the PDB file.
  ntdll.dll!00007fff58b6841f() Unknown Non-user code. Cannot find or open the PDB file.
  ntdll.dll!00007fff58b6831a() Unknown Non-user code. Cannot find or open the PDB file.
  ucrtbase.dll!00007fff55071bf9() Unknown Non-user code. Cannot find or open the PDB file.
> csound64.dll!corfile_flush(CORFIL * f) Line 109 C Symbols loaded.
  csound64.dll!csoundCompileArgs(CSOUND_ * csound, int argc, const char * * argv) Line 211 C Symbols loaded.
  csound64.dll!csoundCompile(CSOUND_ * csound, int argc, const char * * argv) Line 507 C Symbols loaded.
  csound.exe!main(int argc, char * * argv) Line 320 C Symbols loaded.
  [External Code] Annotated Frame

Any help appreciated here!
steven


Date2017-10-20 21:12
FromVictor Lazzarini
SubjectRe: [Csnd-dev] Crashes (mrealloc?)
on OSX, running on lldb I was getting the server suddenly stopping. Just to be sure it wasn’t the new async code, I changed it back to use
the lock-based function. I got then a stop and a crash. Here’s the backtrace

frame #0: 0x00000001025b4a98 libportaudio.2.dylib`TerminateHostApis + 40
    frame #1: 0x00000001025b5976 libportaudio.2.dylib`Pa_Terminate + 70
    frame #2: 0x0000000105eb4f7d librtpa.dylib`csoundModuleDestroy(csound=0x0000000101800a00) at rtpa.c:890
    frame #3: 0x0000000100268315 CsoundLib64`csoundDestroyModules(csound=0x0000000101800a00) at csmodule.c:660
    frame #4: 0x00000001000925c8 CsoundLib64`reset(csound=0x0000000101800a00) at csound.c:3093
    frame #5: 0x000000010009248e CsoundLib64`csoundDestroy(csound=0x0000000101800a00) at csound.c:1303
    frame #6: 0x00000001000910aa CsoundLib64`destroy_all_instances at csound.c:948
    frame #7: 0x00007fffc3cb717f libsystem_c.dylib`__cxa_finalize_ranges + 339
    frame #8: 0x00007fffc3cb74b2 libsystem_c.dylib`exit + 55
    frame #9: 0x00000001000c15c0 CsoundLib64`mrealloc(csound=0x0000000101800a00, oldp=0x0000000100b70710, size=56) at memalloc.c:201
    frame #10: 0x00000001001dc2ea CsoundLib64`tabcopy(csound=0x0000000101800a00, p=0x0000000101057a98) at arrays.c:1443
    frame #11: 0x00000001000b3c7e CsoundLib64`init0(csound=0x0000000101800a00) at insert.c:64
    frame #12: 0x00000001003930ab CsoundLib64`merge_state(csound=0x0000000101800a00, engineState=0x0000000100a9e540, typetable=0x0000000100a9de90, ids=0x0000000000000000) at csound_orc_compile.c:1450
    frame #13: 0x0000000100393fba CsoundLib64`csoundCompileTreeInternal(csound=0x0000000101800a00, root=0x0000000100a9cf00, async=0) at csound_orc_compile.c:1715
    frame #14: 0x00000001003945b4 CsoundLib64`csoundCompileOrcInternal(csound=0x0000000101800a00, str="gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)\n", async=0) at csound_orc_compile.c:1803
    frame #15: 0x0000000100273139 CsoundLib64`csoundCompileOrc(csound=0x0000000101800a00, str="gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)\n") at threadsafe.c:452
    frame #16: 0x0000000100274a70 CsoundLib64`udp_recv(pdata=0x0000000100b7afd0) at server.c:161
    frame #17: 0x00007fffc3e3b93b libsystem_pthread.dylib`_pthread_body + 180
    frame #18: 0x00007fffc3e3b887 libsystem_pthread.dylib`_pthread_start + 286
    frame #19: 0x00007fffc3e3b08d libsystem_pthread.dylib`thread_start + 13

Something seems to be making Csound exit the processing and then call destroy (a fail in kperf()?)


========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 20 Oct 2017, at 20:44, Steven Yi  wrote:
> 
> Hi All,
> 
> I've been chasing down a crash and it's been hard to diagnose.  Attached is an updated copy of of the live coding code I've been working. I have been re-evaluating live the following code:
> 
> gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)
> 
> modifying the arguments to fillarray() to changes the contents of the gkscale array.  I can modify and re-evaluate and get updated values (using csound as UDP server with --port=10000) but then it will eventually crash when I do an eval.
> 
> 
> I've tried a few ways of debugging. I have been using MinGW-compiled csound primarily for regular work at this time.  This is built using RelWithDebInfo.  When I run csound from the commandline with "-odac live0.csd --port=10000" and send code from Vim to eval, I would eventually get a crash.  If I run the same csound under GDB, it does not crash.
> 
> Using Visual Studio compiled builds, I get different behavior.  With RelWithDebInfo build and running within VS, I get a crash and it traces to a failure in memalloc.c:mrealloc():
> 
>     /* allocate memory */
>     p = realloc((void*) pp, ALLOC_BYTES(size));
> 
> Stack trace is as follows: 
> 
>  	ntdll.dll!00007fff58c3771e()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ntdll.dll!00007fff58c3df0a()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ntdll.dll!00007fff58be4f22()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ntdll.dll!00007fff58bf6a8a()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ntdll.dll!00007fff58b6831a()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ucrtbase.dll!00007fff55071bf9()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	csound64.dll!mrealloc(CSOUND_ * csound, void * oldp, unsigned __int64 size) Line 208	C	Symbols loaded.
> >	csound64.dll!tabcopy(CSOUND_ * csound, TABCPY * p) Line 1445	C	Symbols loaded.
>  	csound64.dll!init0(CSOUND_ * csound) Line 64	C	Symbols loaded.
>  	csound64.dll!merge_state(CSOUND_ * csound, engine_state * engineState, type_table * typetable, opds * ids) Line 1452	C	Symbols loaded.
>  	csound64.dll!message_dequeue(CSOUND_ * csound) Line 247	C	Symbols loaded.
>  	csound64.dll!kperf_nodebug(CSOUND_ * csound) Line 1582	C	Symbols loaded.
>  	csound64.dll!csoundPerform(CSOUND_ * csound) Line 2155	C	Symbols loaded.
>  	csound.exe!main(int argc, char * * argv) Line 325	C	Symbols loaded.
>  	[External Code]		Annotated Frame
> 
> I seem to get this consistently if I use change size of the array to one size less, then one size bigger again. So the code I would evaluate is:
> 
> gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)
> gkscale[] = fillarray(0, 2, 3, 5, 7, 8)
> gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)
> 
> one line at a time. 
> 
> I tried using a Debug build of Visual Studio, but it crashes in realloc very early in the program:
> 
>  	ntdll.dll!00007fff58b686c8()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ntdll.dll!00007fff58b6841f()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ntdll.dll!00007fff58b6831a()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ucrtbase.dll!00007fff55071bf9()	Unknown	Non-user code. Cannot find or open the PDB file.
> >	csound64.dll!corfile_flush(CORFIL * f) Line 109	C	Symbols loaded.
>  	csound64.dll!csoundCompileArgs(CSOUND_ * csound, int argc, const char * * argv) Line 211	C	Symbols loaded.
>  	csound64.dll!csoundCompile(CSOUND_ * csound, int argc, const char * * argv) Line 507	C	Symbols loaded.
>  	csound.exe!main(int argc, char * * argv) Line 320	C	Symbols loaded.
>  	[External Code]		Annotated Frame
> 
> Any help appreciated here!
>

Date2017-10-20 21:15
FromVictor Lazzarini
SubjectRe: [Csnd-dev] Crashes (mrealloc?)
Running outside the debugger, with the async code, I get

csound(3456,0x7fffccb3f3c0) malloc: *** error for object 0x7fcc214d4f48: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug

I am wondering whether we’re calling mrealloc on something already freed?

========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 20 Oct 2017, at 20:44, Steven Yi  wrote:
> 
> Hi All,
> 
> I've been chasing down a crash and it's been hard to diagnose.  Attached is an updated copy of of the live coding code I've been working. I have been re-evaluating live the following code:
> 
> gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)
> 
> modifying the arguments to fillarray() to changes the contents of the gkscale array.  I can modify and re-evaluate and get updated values (using csound as UDP server with --port=10000) but then it will eventually crash when I do an eval.
> 
> 
> I've tried a few ways of debugging. I have been using MinGW-compiled csound primarily for regular work at this time.  This is built using RelWithDebInfo.  When I run csound from the commandline with "-odac live0.csd --port=10000" and send code from Vim to eval, I would eventually get a crash.  If I run the same csound under GDB, it does not crash.
> 
> Using Visual Studio compiled builds, I get different behavior.  With RelWithDebInfo build and running within VS, I get a crash and it traces to a failure in memalloc.c:mrealloc():
> 
>     /* allocate memory */
>     p = realloc((void*) pp, ALLOC_BYTES(size));
> 
> Stack trace is as follows: 
> 
>  	ntdll.dll!00007fff58c3771e()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ntdll.dll!00007fff58c3df0a()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ntdll.dll!00007fff58be4f22()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ntdll.dll!00007fff58bf6a8a()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ntdll.dll!00007fff58b6831a()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ucrtbase.dll!00007fff55071bf9()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	csound64.dll!mrealloc(CSOUND_ * csound, void * oldp, unsigned __int64 size) Line 208	C	Symbols loaded.
> >	csound64.dll!tabcopy(CSOUND_ * csound, TABCPY * p) Line 1445	C	Symbols loaded.
>  	csound64.dll!init0(CSOUND_ * csound) Line 64	C	Symbols loaded.
>  	csound64.dll!merge_state(CSOUND_ * csound, engine_state * engineState, type_table * typetable, opds * ids) Line 1452	C	Symbols loaded.
>  	csound64.dll!message_dequeue(CSOUND_ * csound) Line 247	C	Symbols loaded.
>  	csound64.dll!kperf_nodebug(CSOUND_ * csound) Line 1582	C	Symbols loaded.
>  	csound64.dll!csoundPerform(CSOUND_ * csound) Line 2155	C	Symbols loaded.
>  	csound.exe!main(int argc, char * * argv) Line 325	C	Symbols loaded.
>  	[External Code]		Annotated Frame
> 
> I seem to get this consistently if I use change size of the array to one size less, then one size bigger again. So the code I would evaluate is:
> 
> gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)
> gkscale[] = fillarray(0, 2, 3, 5, 7, 8)
> gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)
> 
> one line at a time. 
> 
> I tried using a Debug build of Visual Studio, but it crashes in realloc very early in the program:
> 
>  	ntdll.dll!00007fff58b686c8()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ntdll.dll!00007fff58b6841f()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ntdll.dll!00007fff58b6831a()	Unknown	Non-user code. Cannot find or open the PDB file.
>  	ucrtbase.dll!00007fff55071bf9()	Unknown	Non-user code. Cannot find or open the PDB file.
> >	csound64.dll!corfile_flush(CORFIL * f) Line 109	C	Symbols loaded.
>  	csound64.dll!csoundCompileArgs(CSOUND_ * csound, int argc, const char * * argv) Line 211	C	Symbols loaded.
>  	csound64.dll!csoundCompile(CSOUND_ * csound, int argc, const char * * argv) Line 507	C	Symbols loaded.
>  	csound.exe!main(int argc, char * * argv) Line 320	C	Symbols loaded.
>  	[External Code]		Annotated Frame
> 
> Any help appreciated here!
> steve

Date2017-10-20 21:30
FromSteven Yi
SubjectRe: [Csnd-dev] Crashes (mrealloc?)
Thanks Victor for taking a look, it's good to get confirmation and to see that the problem is not just on Windows.  Perhaps something is not quite right with merging? I'll fire up the old OSX computer to see if I can find any more information using XCode. 

On Fri, Oct 20, 2017 at 4:15 PM, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
Running outside the debugger, with the async code, I get

csound(3456,0x7fffccb3f3c0) malloc: *** error for object 0x7fcc214d4f48: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug

I am wondering whether we’re calling mrealloc on something already freed?

========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 20 Oct 2017, at 20:44, Steven Yi <stevenyi@gmail.com> wrote:
>
> Hi All,
>
> I've been chasing down a crash and it's been hard to diagnose.  Attached is an updated copy of of the live coding code I've been working. I have been re-evaluating live the following code:
>
> gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)
>
> modifying the arguments to fillarray() to changes the contents of the gkscale array.  I can modify and re-evaluate and get updated values (using csound as UDP server with --port=10000) but then it will eventually crash when I do an eval.
>
>
> I've tried a few ways of debugging. I have been using MinGW-compiled csound primarily for regular work at this time.  This is built using RelWithDebInfo.  When I run csound from the commandline with "-odac live0.csd --port=10000" and send code from Vim to eval, I would eventually get a crash.  If I run the same csound under GDB, it does not crash.
>
> Using Visual Studio compiled builds, I get different behavior.  With RelWithDebInfo build and running within VS, I get a crash and it traces to a failure in memalloc.c:mrealloc():
>
>     /* allocate memory */
>     p = realloc((void*) pp, ALLOC_BYTES(size));
>
> Stack trace is as follows:
>
>       ntdll.dll!00007fff58c3771e()    Unknown Non-user code. Cannot find or open the PDB file.
>       ntdll.dll!00007fff58c3df0a()    Unknown Non-user code. Cannot find or open the PDB file.
>       ntdll.dll!00007fff58be4f22()    Unknown Non-user code. Cannot find or open the PDB file.
>       ntdll.dll!00007fff58bf6a8a()    Unknown Non-user code. Cannot find or open the PDB file.
>       ntdll.dll!00007fff58b6831a()    Unknown Non-user code. Cannot find or open the PDB file.
>       ucrtbase.dll!00007fff55071bf9() Unknown Non-user code. Cannot find or open the PDB file.
>       csound64.dll!mrealloc(CSOUND_ * csound, void * oldp, unsigned __int64 size) Line 208    C       Symbols loaded.
> >     csound64.dll!tabcopy(CSOUND_ * csound, TABCPY * p) Line 1445    C       Symbols loaded.
>       csound64.dll!init0(CSOUND_ * csound) Line 64    C       Symbols loaded.
>       csound64.dll!merge_state(CSOUND_ * csound, engine_state * engineState, type_table * typetable, opds * ids) Line 1452    C       Symbols loaded.
>       csound64.dll!message_dequeue(CSOUND_ * csound) Line 247 C       Symbols loaded.
>       csound64.dll!kperf_nodebug(CSOUND_ * csound) Line 1582  C       Symbols loaded.
>       csound64.dll!csoundPerform(CSOUND_ * csound) Line 2155  C       Symbols loaded.
>       csound.exe!main(int argc, char * * argv) Line 325       C       Symbols loaded.
>       [External Code]         Annotated Frame
>
> I seem to get this consistently if I use change size of the array to one size less, then one size bigger again. So the code I would evaluate is:
>
> gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)
> gkscale[] = fillarray(0, 2, 3, 5, 7, 8)
> gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)
>
> one line at a time.
>
> I tried using a Debug build of Visual Studio, but it crashes in realloc very early in the program:
>
>       ntdll.dll!00007fff58b686c8()    Unknown Non-user code. Cannot find or open the PDB file.
>       ntdll.dll!00007fff58b6841f()    Unknown Non-user code. Cannot find or open the PDB file.
>       ntdll.dll!00007fff58b6831a()    Unknown Non-user code. Cannot find or open the PDB file.
>       ucrtbase.dll!00007fff55071bf9() Unknown Non-user code. Cannot find or open the PDB file.
> >     csound64.dll!corfile_flush(CORFIL * f) Line 109 C       Symbols loaded.
>       csound64.dll!csoundCompileArgs(CSOUND_ * csound, int argc, const char * * argv) Line 211        C       Symbols loaded.
>       csound64.dll!csoundCompile(CSOUND_ * csound, int argc, const char * * argv) Line 507    C       Symbols loaded.
>       csound.exe!main(int argc, char * * argv) Line 320       C       Symbols loaded.
>       [External Code]         Annotated Frame
>
> Any help appreciated here!
> steven
>
> <live0.csd>



Date2017-10-20 21:45
FromVictor Lazzarini
SubjectRe: [Csnd-dev] Crashes (mrealloc?)
I don’t think it’s anything to do with compilation or merging, because if I add this to the CSD

 instr 100
gkscale[] = fillarray(0, 2, 3, 4, 5 ,6,7,8, 9, 10, 11);
endin

instr 101
gkscale[] = fillarray(0, 2);
endin

schedule(100, 3, 1)
schedule(101,4,1)

and run it (no server) I get

new alloc for instr 101:
csound(8008,0x70000b31d000) malloc: *** error for object 0x7f9bbbd8d768: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug

csound command: Abort trap


it looks like something in the tapcopy() (array copy).
========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 20 Oct 2017, at 21:30, Steven Yi  wrote:
> 
> Thanks Victor for taking a look, it's good to get confirmation and to see that the problem is not just on Windows.  Perhaps something is not quite right with merging? I'll fire up the old OSX computer to see if I can find any more information using XCode. 
> 
> On Fri, Oct 20, 2017 at 4:15 PM, Victor Lazzarini  wrote:
> Running outside the debugger, with the async code, I get
> 
> csound(3456,0x7fffccb3f3c0) malloc: *** error for object 0x7fcc214d4f48: incorrect checksum for freed object - object was probably modified after being freed.
> *** set a breakpoint in malloc_error_break to debug
> 
> I am wondering whether we’re calling mrealloc on something already freed?
> 
> ========================
> Prof. Victor Lazzarini
> Dean of Arts, Celtic Studies, and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
> 
> > On 20 Oct 2017, at 20:44, Steven Yi  wrote:
> >
> > Hi All,
> >
> > I've been chasing down a crash and it's been hard to diagnose.  Attached is an updated copy of of the live coding code I've been working. I have been re-evaluating live the following code:
> >
> > gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)
> >
> > modifying the arguments to fillarray() to changes the contents of the gkscale array.  I can modify and re-evaluate and get updated values (using csound as UDP server with --port=10000) but then it will eventually crash when I do an eval.
> >
> >
> > I've tried a few ways of debugging. I have been using MinGW-compiled csound primarily for regular work at this time.  This is built using RelWithDebInfo.  When I run csound from the commandline with "-odac live0.csd --port=10000" and send code from Vim to eval, I would eventually get a crash.  If I run the same csound under GDB, it does not crash.
> >
> > Using Visual Studio compiled builds, I get different behavior.  With RelWithDebInfo build and running within VS, I get a crash and it traces to a failure in memalloc.c:mrealloc():
> >
> >     /* allocate memory */
> >     p = realloc((void*) pp, ALLOC_BYTES(size));
> >
> > Stack trace is as follows:
> >
> >       ntdll.dll!00007fff58c3771e()    Unknown Non-user code. Cannot find or open the PDB file.
> >       ntdll.dll!00007fff58c3df0a()    Unknown Non-user code. Cannot find or open the PDB file.
> >       ntdll.dll!00007fff58be4f22()    Unknown Non-user code. Cannot find or open the PDB file.
> >       ntdll.dll!00007fff58bf6a8a()    Unknown Non-user code. Cannot find or open the PDB file.
> >       ntdll.dll!00007fff58b6831a()    Unknown Non-user code. Cannot find or open the PDB file.
> >       ucrtbase.dll!00007fff55071bf9() Unknown Non-user code. Cannot find or open the PDB file.
> >       csound64.dll!mrealloc(CSOUND_ * csound, void * oldp, unsigned __int64 size) Line 208    C       Symbols loaded.
> > >     csound64.dll!tabcopy(CSOUND_ * csound, TABCPY * p) Line 1445    C       Symbols loaded.
> >       csound64.dll!init0(CSOUND_ * csound) Line 64    C       Symbols loaded.
> >       csound64.dll!merge_state(CSOUND_ * csound, engine_state * engineState, type_table * typetable, opds * ids) Line 1452    C       Symbols loaded.
> >       csound64.dll!message_dequeue(CSOUND_ * csound) Line 247 C       Symbols loaded.
> >       csound64.dll!kperf_nodebug(CSOUND_ * csound) Line 1582  C       Symbols loaded.
> >       csound64.dll!csoundPerform(CSOUND_ * csound) Line 2155  C       Symbols loaded.
> >       csound.exe!main(int argc, char * * argv) Line 325       C       Symbols loaded.
> >       [External Code]         Annotated Frame
> >
> > I seem to get this consistently if I use change size of the array to one size less, then one size bigger again. So the code I would evaluate is:
> >
> > gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)
> > gkscale[] = fillarray(0, 2, 3, 5, 7, 8)
> > gkscale[] = fillarray(0, 2, 3, 5, 7, 8, 10)
> >
> > one line at a time.
> >
> > I tried using a Debug build of Visual Studio, but it crashes in realloc very early in the program:
> >
> >       ntdll.dll!00007fff58b686c8()    Unknown Non-user code. Cannot find or open the PDB file.
> >       ntdll.dll!00007fff58b6841f()    Unknown Non-user code. Cannot find or open the PDB file.
> >       ntdll.dll!00007fff58b6831a()    Unknown Non-user code. Cannot find or open the PDB file.
> >       ucrtbase.dll!00007fff55071bf9() Unknown Non-user code. Cannot find or open the PDB file.
> > >     csound64.dll!corfile_flush(CORFIL * f) Line 109 C       Symbols loaded.
> >       csound64.dll!csoundCompileArgs(CSOUND_ * csound, int argc, const char * * argv) Line 211        C       Symbols loaded.
> >       csound64.dll!csoundCompile(CSOUND_ * csound, int argc, const char * * argv) Line 507    C       Symbols loaded.
> >       csound.exe!main(int argc, char * * argv) Line 320       C       Symbols loaded.
> >       [External Code]         Annotated Frame
> >
> > Any help appreciated here!
> > steven
> >
> > 
> 
> 

Date2017-10-20 21:52
Fromjpff
SubjectRe: [Csnd-dev] Crashes (mrealloc?)
valgrind is the tool to find memory failures-- but i think that 

Date2017-10-20 21:58
Fromjpff
SubjectRe: [Csnd-dev] Crashes (mrealloc?)
I ran your live0.csd for 45mins of output without a crash.  How long 
should i wait?

Date2017-10-20 22:00
FromVictor Lazzarini
SubjectRe: [Csnd-dev] Crashes (mrealloc?)
Attachmentslive0.csd  
Can you run this modified version?

========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 20 Oct 2017, at 21:58, jpff <jpff@CODEMIST.CO.UK> wrote:
>
> I ran your live0.csd for 45mins of output without a crash.  How long should i wait?
>
> Or do I have to do something --i think i am confused


Date2017-10-20 22:00
FromSteven Yi
SubjectRe: [Csnd-dev] Crashes (mrealloc?)
I think I found it! As usual, the problem was obvious after looking at it.  Realloc was not used correctly and the returned value was not reassigned to p->dst->data.  

I'm now not getting crashes when redefining that array. :) I've pushed the fix to Git. 

One thing: should we be reusing tabensure in arrays.c for the code that is using csound->ReAlloc() directly?



On Fri, Oct 20, 2017 at 4:52 PM, jpff <jpff@codemist.co.uk> wrote:
valgrind is the tool to find memory failures-- but i think that is Linux-only?


Date2017-10-20 22:05
FromVictor Lazzarini
SubjectRe: [Csnd-dev] Crashes (mrealloc?)
yep, I saw that now, quite obvious.
========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 20 Oct 2017, at 22:00, Steven Yi  wrote:
> 
> I think I found it! As usual, the problem was obvious after looking at it.  Realloc was not used correctly and the returned value was not reassigned to p->dst->data.  
> 
> I'm now not getting crashes when redefining that array. :) I've pushed the fix to Git. 
> 
> One thing: should we be reusing tabensure in arrays.c for the code that is using csound->ReAlloc() directly?
> 
> 
> 
> On Fri, Oct 20, 2017 at 4:52 PM, jpff  wrote:
> valgrind is the tool to find memory failures-- but i think that is Linux-only?

Date2017-10-20 22:07
FromVictor Lazzarini
SubjectRe: [Csnd-dev] Crashes (mrealloc?)
By the way, the hex beats work very well.
========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 20 Oct 2017, at 22:05, Victor Lazzarini  wrote:
> 
> yep, I saw that now, quite obvious.
> ========================
> Prof. Victor Lazzarini
> Dean of Arts, Celtic Studies, and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952 
> 
>> On 20 Oct 2017, at 22:00, Steven Yi  wrote:
>> 
>> I think I found it! As usual, the problem was obvious after looking at it.  Realloc was not used correctly and the returned value was not reassigned to p->dst->data.  
>> 
>> I'm now not getting crashes when redefining that array. :) I've pushed the fix to Git. 
>> 
>> One thing: should we be reusing tabensure in arrays.c for the code that is using csound->ReAlloc() directly?
>> 
>> 
>> 
>> On Fri, Oct 20, 2017 at 4:52 PM, jpff  wrote:
>> valgrind is the tool to find memory failures-- but i think that is Linux-only?

Date2017-10-20 22:09
Fromjpff
SubjectRe: [Csnd-dev] Crashes (mrealloc?)
==19408== Invalid write of size 8
==19408==    at 0x4C2F9C7: memset (in 
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==19408==    by 0x4F3E04E: tabcopy (arrays.c:1445)
==19408==    by 0x4E91B08: insert (insert.c:300)
==19408==    by 0x4E965C5: process_score_event (musmon.c:777)
==19408==    by 0x4E9715A: process_rt_event (musmon.c:872)
==19408==    by 0x4E98FB8: sensevents (musmon.c:1061)
==19408==    by 0x4E7AA61: csoundPerform (csound.c:2146)
==19408==    by 0x40155E: main (csound_main.c:322)
==19408==  Address 0x1ad8ba40 is 16 bytes inside a block of size 72 free'd
==19408==    at 0x4C2B47E: realloc (in 
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==19408==    by 0x4E94AE0: mrealloc (memalloc.c:208)
==19408==    by 0x4F3E031: tabcopy (arrays.c:1443)
==19408==    by 0x4E91B08: insert (insert.c:300)
==19408==    by 0x4E965C5: process_score_event (musmon.c:777)
==19408==    by 0x4E9715A: process_rt_event (musmon.c:872)
==19408==    by 0x4E98FB8: sensevents (musmon.c:1061)
==19408==    by 0x4E7AA61: csoundPerform (csound.c:2146)
==19408==    by 0x40155E: main (csound_main.c:322)
==19408==  Block was alloc'd at
==19408==    at 0x4C2B240: calloc (in 
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==19408==    by 0x4E948A7: mcalloc (memalloc.c:113)
==19408==    by 0x4F3E130: tabcopy (arrays.c:1440)
==19408==    by 0x4E8E3B8: init0 (insert.c:64)
==19408==    by 0x4E97631: musmon (musmon.c:233)
==19408==    by 0x4FAEAE6: csoundStart (main.c:502)
==19408==    by 0x401516: main (csound_main.c:320)
==19408==
==19408== Invalid write of size 8


On Fri, 20 Oct 2017, Victor Lazzarini wrote:

> Can you run this modified version?
> 
> ========================
> Prof. Victor Lazzarini
> Dean of Arts, Celtic Studies, and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
> 
> > On 20 Oct 2017, at 21:58, jpff  wrote:
> >
> > I ran your live0.csd for 45mins of output without a crash.  How long should
> i wait?
> >
> > Or do I have to do something --i think i am confused
> 
> 
>

Date2017-10-20 22:20
FromSteven Yi
SubjectRe: [Csnd-dev] Crashes (mrealloc?)
Thanks again for the retest! Glad it's working now there (I was back on Windows when I found the fix and tested only with VS and MinGW).  

On Fri, Oct 20, 2017 at 5:07 PM, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
By the way, the hex beats work very well.
========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 20 Oct 2017, at 22:05, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
>
> yep, I saw that now, quite obvious.
> ========================
> Prof. Victor Lazzarini
> Dean of Arts, Celtic Studies, and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
>
>> On 20 Oct 2017, at 22:00, Steven Yi <stevenyi@gmail.com> wrote:
>>
>> I think I found it! As usual, the problem was obvious after looking at it.  Realloc was not used correctly and the returned value was not reassigned to p->dst->data.
>>
>> I'm now not getting crashes when redefining that array. :) I've pushed the fix to Git.
>>
>> One thing: should we be reusing tabensure in arrays.c for the code that is using csound->ReAlloc() directly?
>>
>>
>>
>> On Fri, Oct 20, 2017 at 4:52 PM, jpff <jpff@codemist.co.uk> wrote:
>> valgrind is the tool to find memory failures-- but i think that is Linux-only?
>>