db3108 / michi-c2

Michi-c2 --- development version for michi-c
25 stars 9 forks source link

crash on clear_board twice #12

Closed horaceho closed 8 years ago

horaceho commented 8 years ago

When I try to open a sgf file via GoGUI, michi-c2 crashes. Then I traced the issue is caused by two consequtive clear_board. To reproduce:

$ ./michi gtp
clear_board
Move: 0     Black: 0 caps   White: 0 caps   Komi: 7.5
 19 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 18 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 17 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 16 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 15 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 14 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 13 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 12 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 11 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 10 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 9  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 8  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 7  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 6  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 5  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 4  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 3  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 2  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 1  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
    A B C D E F G H J K L M N O P Q R S T 

= 

clear_board
michi(27531,0x7fff78670300) malloc: *** error for object 0x7f93f8405070: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
traveller42 commented 8 years ago

How very odd.

What system are you running on? I assume you are running the current master commit. If not, which commit? What version of the compiler are you using?

db3108 commented 8 years ago

Hello Horace,

The question of traveller42 is interesting because I cannot reproduce on my Linux box (64 bits) the crash caused by successive clear_board() that you report.

In addition, I've just had a look at the code and I couldn't find any obvious reason why the code could crash on the second call to game_clear_board(). The sequence of instructions that are executed is pretty simple and does not involve any memory allocation or pointer assignement. So I suspect that the error message that you report above is caused by a memory corruption that change the code. However, on my system, the tests (with valgrind) run without detecting any problem.

If you send me the sgf file that is at the origin of this issue, I could try to see if I get an error when loading it.

Best, Denis

horaceho commented 8 years ago

I am running the https://github.com/db3108/michi-c2/commit/796eedd8a9404148d1b6d44cc2d63e803ffbaa2b on my MacBook, OS X 10.10.5

traveller42 commented 8 years ago

Just rebuilt on my Linux system, Xubuntu 5.10 (64-bit), using the default C compiler, gcc (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010, and I cannot reproduce the error.

Can you rebuild from scratch and send us a copy of the output from the build? Can you send us the contents of michi.log from the directory where you ran it?

This will help with locating where in the sequence the issue is occurring.

horaceho commented 8 years ago

I have also compiled and tested the code on Ubuntu 14.04 without any error:

$ make
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 ui.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 sgf.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 control.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 michi.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 params.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 board.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 board_util.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 patterns.c 
patterns.c: In function ‘init_large_patterns’:
patterns.c:651:50: warning: ‘fspat’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     if (verbosity > 0 && (fprob == NULL || fspat == NULL)) {
                                                  ^
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 debug.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 main.c 
gcc -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -std=gnu99 -o michi ui.o sgf.o control.o michi.o params.o board.o board_util.o patterns.o debug.o main.o -lm
$ ./michi gtp
Warning: michi cannot load pattern files, It will be much weaker. Consider lowering EXPAND_VISITS 8->2
clear_board
Move: 0     Black: 0 caps   White: 0 caps   Komi: 7.5
 19 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 18 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 17 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 16 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 15 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 14 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 13 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 12 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 11 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 10 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 9  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 8  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 7  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 6  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 5  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 4  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 3  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 2  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 1  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
    A B C D E F G H J K L M N O P Q R S T 

= 

clear_board
Move: 0     Black: 0 caps   White: 0 caps   Komi: 7.5
 19 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 18 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 17 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 16 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 15 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 14 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 13 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 12 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 11 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 10 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 9  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 8  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 7  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 6  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 5  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 4  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 3  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 2  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 1  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
    A B C D E F G H J K L M N O P Q R S T 

= 

clear_board
Move: 0     Black: 0 caps   White: 0 caps   Komi: 7.5
 19 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 18 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 17 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 16 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 15 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 14 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 13 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 12 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 11 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 10 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 9  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 8  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 7  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 6  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 5  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 4  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 3  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 2  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 1  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
    A B C D E F G H J K L M N O P Q R S T 

= 

quit
= 

Here is the version of code I am using, on dropbox.

Here is the compile and run log on Mac OS X 10.10.5, with malloc error:

Air:michi-c2-796eedd horace$ make
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 ui.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 sgf.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 control.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 michi.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 params.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 board.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 board_util.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 patterns.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 debug.c 
gcc  -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -c -std=gnu99 main.c 
gcc -DNDEBUG -O3 -march=native -msse4 -fshort-enums -Wall -Wno-char-subscripts -std=gnu99 -o michi ui.o sgf.o control.o michi.o params.o board.o board_util.o patterns.o debug.o main.o -lm
Air:michi-c2-796eedd horace$ ./michi gtp
Warning: michi cannot load pattern files, It will be much weaker. Consider lowering EXPAND_VISITS 8->2
clear_board
Move: 0     Black: 0 caps   White: 0 caps   Komi: 7.5
 19 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 18 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 17 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 16 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 15 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 14 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 13 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 12 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 11 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 10 . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 9  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 8  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 7  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 6  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 5  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 4  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 3  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 2  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
 1  . . . . . . . . . . . . . . . . . . .     . . . . . . . . . . . . . . . . . . .
    A B C D E F G H J K L M N O P Q R S T 

= 

clear_board
michi(30447,0x7fff78670300) malloc: *** error for object 0x7fd87a404cd0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

Here is the michi.log:

I     0/000 michi-c Version 1.4
I     0/000 size of struct Position = 14540 bytes
I     0/000 size of struct TreeNode = 40 bytes
I     0/000 size of int  = 4 bytes
I     0/000 size of long = 8 bytes
T     0/000 time          :  nsims seconds  sims/s moves tleft
S     0/000 search: idum dkomi 1st (2nd) best2  bestr bestwr games/s
I     0/000 Loading pattern probs ...
w     0/000 Cannot load pattern file:patterns.prob
I     0/000 =========== Hashtable initialization synthesis ==========
C     0/000 clear_board
I     1/001 BEGIN GAME 1, random seed = 3698499369
C     1/001 clear_board
horaceho commented 8 years ago

Some more information ...

If I the run the code in Xcode and enable one of the following diagnostic options:

Xcode is able to catch the error and generates an EXC_BAD_ACCESS.

bad

traveller42 commented 8 years ago

Thanks for that last comment, @horaceho. That was the key I needed.

horaceho commented 8 years ago

https://github.com/db3108/michi-c2/pull/14 fixes the issue. Thank you.