Skip to content

Commit 953dfa3

Browse files
committed
vinyl: fix memory leak on dump/compaction failure
The issue is we increment `page_count` only on page write. If we fail for some reason before then page info `min_key` in leaked. LSAN report for 'vinyl/recovery_quota.test.lua': ``` 2024-07-05 13:30:34.605 [478603] main/103/on_shutdown vy_scheduler.c:1668 E> 512/0: failed to compact range (-inf..inf) ================================================================= ==478603==ERROR: LeakSanitizer: detected memory leaks Direct leak of 4 byte(s) in 1 object(s) allocated from: #0 0x5e4ebafcae09 in malloc (/home/shiny/dev/tarantool/build-asan-debug/src/tarantool+0x1244e09) (BuildId: 20c5933d67a3831c4f43f6860379d58d35b81974) tarantool#1 0x5e4ebb3f9b69 in vy_key_dup /home/shiny/dev/tarantool/src/box/vy_stmt.c:308:14 tarantool#2 0x5e4ebb49b615 in vy_page_info_create /home/shiny/dev/tarantool/src/box/vy_run.c:257:23 tarantool#3 0x5e4ebb48f59f in vy_run_writer_start_page /home/shiny/dev/tarantool/src/box/vy_run.c:2196:6 tarantool#4 0x5e4ebb48c6b6 in vy_run_writer_append_stmt /home/shiny/dev/tarantool/src/box/vy_run.c:2287:6 tarantool#5 0x5e4ebb72877f in vy_task_write_run /home/shiny/dev/tarantool/src/box/vy_scheduler.c:1132:8 tarantool#6 0x5e4ebb73305e in vy_task_compaction_execute /home/shiny/dev/tarantool/src/box/vy_scheduler.c:1485:9 tarantool#7 0x5e4ebb73e152 in vy_task_f /home/shiny/dev/tarantool/src/box/vy_scheduler.c:1795:6 tarantool#8 0x5e4ebb01e0b1 in fiber_cxx_invoke(int (*)(__va_list_tag*), __va_list_tag*) /home/shiny/dev/tarantool/src/lib/core/fiber.h:1331:10 tarantool#9 0x5e4ebc389ee0 in fiber_loop /home/shiny/dev/tarantool/src/lib/core/fiber.c:1182:18 tarantool#10 0x5e4ebd3e9595 in coro_init /home/shiny/dev/tarantool/third_party/coro/coro.c:108:3 SUMMARY: AddressSanitizer: 4 byte(s) leaked in 1 allocation(s). ``` NO_TEST=covered by existing tests (ASAN build) NO_DOC=bugfix
1 parent a4f4569 commit 953dfa3

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## bugfix/vinyl
2+
3+
- Fixed memory leak in vinyl on dump/compaction failure.

src/box/vy_run.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,6 +2196,7 @@ vy_run_writer_start_page(struct vy_run_writer *writer,
21962196
if (vy_page_info_create(page, writer->data_xlog.offset,
21972197
key, writer->cmp_def) != 0)
21982198
return -1;
2199+
run->info.page_count++;
21992200
xlog_tx_begin(&writer->data_xlog);
22002201
return 0;
22012202
}
@@ -2219,7 +2220,7 @@ vy_run_writer_write_to_page(struct vy_run_writer *writer, struct vy_entry entry)
22192220
writer->last = entry;
22202221
vy_stmt_ref_if_possible(entry.stmt);
22212222
struct vy_run *run = writer->run;
2222-
struct vy_page_info *page = run->page_info + run->info.page_count;
2223+
struct vy_page_info *page = run->page_info + run->info.page_count - 1;
22232224
uint32_t *offset = (uint32_t *)ibuf_alloc(&writer->row_index_buf,
22242225
sizeof(uint32_t));
22252226
if (offset == NULL) {
@@ -2247,7 +2248,8 @@ static int
22472248
vy_run_writer_end_page(struct vy_run_writer *writer)
22482249
{
22492250
struct vy_run *run = writer->run;
2250-
struct vy_page_info *page = run->page_info + run->info.page_count;
2251+
assert(run->info.page_count > 0);
2252+
struct vy_page_info *page = run->page_info + run->info.page_count - 1;
22512253

22522254
assert(page->row_count > 0);
22532255
assert(ibuf_used(&writer->row_index_buf) ==
@@ -2269,7 +2271,6 @@ vy_run_writer_end_page(struct vy_run_writer *writer)
22692271
if (written < 0)
22702272
return -1;
22712273
page->size = written;
2272-
run->info.page_count++;
22732274
vy_run_acct_page(run, page);
22742275
ibuf_reset(&writer->row_index_buf);
22752276
return 0;

0 commit comments

Comments
 (0)