raft icon indicating copy to clipboard operation
raft copied to clipboard

Fix memory leak on snapshot loading.

Open yossigo opened this issue 5 years ago • 2 comments

All nodes expect local should be removed when loading a snapshot, and any prior knowledge about them should be void.

yossigo avatar Oct 08 '18 19:10 yossigo

I'm getting some AddressSanitizer errors on clang. I will need to look at this a little more.

==99515==ERROR: AddressSanitizer: heap-use-after-free on address 0x603000006498 at pc 0x00010f85936a bp 0x7ffee03b9520 sp 0x7ffee03b9518
WRITE of size 8 at 0x603000006498 thread T0
    #0 0x10f859369 in raft_node_set_next_idx raft_node.c:68
    #1 0x10f87f259 in TestRaft_leader_sends_appendentries_when_node_next_index_was_compacted test_snapshotting.c:544
    #2 0x10f8844fd in CuTestRun CuTest.c:132
    #3 0x10f885b0e in CuSuiteRun CuTest.c:262
    #4 0x10f85b279 in RunAllTests main_test.c:331
    #5 0x7fff5fc5b014 in start (libdyld.dylib:x86_64+0x1014)

0x603000006498 is located 8 bytes inside of 32-byte region [0x603000006490,0x6030000064b0)
freed by thread T0 here:
    #0 0x10f963fdd in wrap_free (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x56fdd)
    #1 0x10f85394b in raft_begin_load_snapshot raft_server.c:1400
    #2 0x10f87f1e7 in TestRaft_leader_sends_appendentries_when_node_next_index_was_compacted test_snapshotting.c:539
    #3 0x10f8844fd in CuTestRun CuTest.c:132
    #4 0x10f885b0e in CuSuiteRun CuTest.c:262
    #5 0x10f85b279 in RunAllTests main_test.c:331
    #6 0x7fff5fc5b014 in start (libdyld.dylib:x86_64+0x1014)

previously allocated by thread T0 here:
    #0 0x10f964367 in wrap_calloc (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x57367)
    #1 0x10f859136 in raft_node_new raft_node.c:42
    #2 0x10f8511e2 in raft_add_node_internal raft_server.c:973
    #3 0x10f87f009 in TestRaft_leader_sends_appendentries_when_node_next_index_was_compacted test_snapshotting.c:511
    #4 0x10f8844fd in CuTestRun CuTest.c:132
    #5 0x10f885b0e in CuSuiteRun CuTest.c:262
    #6 0x10f85b279 in RunAllTests main_test.c:331
    #7 0x7fff5fc5b014 in start (libdyld.dylib:x86_64+0x1014)

willemt avatar Nov 17 '18 01:11 willemt

@willemt missed that one, a problem with the test that violates proper usage (not re-configuring nodes after snapshot loading).

yossigo avatar Nov 18 '18 12:11 yossigo