Commit f688a31d authored by Kirill Smelkov's avatar Kirill Smelkov

bigfile: RAM must be explicitly free'ed after close

Else on-heap allocated RAM object is leaked. Fixes e.g. the following
error on ASAN:

	Direct leak of 56 byte(s) in 1 object(s) allocated from:
	    #0 0x7fc9ef390518 in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xe9518)
	    #1 0x555ca792f309 in zalloc include/wendelin/utils.h:67
	    #2 0x555ca7935f9a in ram_limited_new bigfile/tests/../../t/t_utils.c:35
	    #3 0x555ca793a0ba in test_file_access_synthetic bigfile/tests/test_virtmem.c:292
	    #4 0x555ca7967bc4 in main bigfile/tests/test_virtmem.c:1121
	    #5 0x7fc9ef0e909a in __libc_start_main ../csu/libc-start.c:308
parent f1931264
/* Wendelin.bigfile | virtual memory benchmarks
* Copyright (C) 2017 Nexedi SA and Contributors.
* Copyright (C) 2017-2019 Nexedi SA and Contributors.
* Kirill Smelkov <kirr@nexedi.com>
*
* This program is free software: you can Use, Study, Modify and Redistribute
......@@ -102,7 +102,7 @@ void bench_pagefault() {
vma_unmap(vma);
fileh_close(fh);
ram_close(ram);
free(ram);
}
int main()
......
......@@ -148,6 +148,7 @@ int main()
ramh_close(ramh);
ram_close(ram);
free(ram);
return 0;
}
/* Wendelin.bigfile | virtual memory tests
* Copyright (C) 2014-2015 Nexedi SA and Contributors.
* Copyright (C) 2014-2019 Nexedi SA and Contributors.
* Kirill Smelkov <kirr@nexedi.com>
*
* This program is free software: you can Use, Study, Modify and Redistribute
......@@ -907,8 +907,8 @@ void test_file_access_synthetic(void)
/* free resources & restore SIGSEGV handler */
ram_close(ram);
ram_close(ram0);
ram_close(ram); free(ram);
ram_close(ram0); free(ram0);
ok1(!sigaction(SIGSEGV, &saveact, NULL));
......@@ -1034,6 +1034,7 @@ void test_file_access_pagefault()
fileh_close(fh);
// ok1(list_empty(&ram->lru_list));
ram_close(ram);
free(ram);
}
......@@ -1104,6 +1105,7 @@ void test_pagefault_savestate()
vma_unmap(vma);
fileh_close(fh);
ram_close(ram);
free(ram);
#undef CHECK_PAGE
#undef CHECK_NOPAGE
......
......@@ -2,7 +2,7 @@
#define _WENDELIN_BIGFILE_RAM_H_
/* Wendelin.bigfile | Interfaces to work with RAM
* Copyright (C) 2014-2015 Nexedi SA and Contributors.
* Copyright (C) 2014-2019 Nexedi SA and Contributors.
* Kirill Smelkov <kirr@nexedi.com>
*
* This program is free software: you can Use, Study, Modify and Redistribute
......@@ -92,9 +92,9 @@ size_t ram_get_current_maxsize(RAM *ram);
RAMH *ramh_open(RAM *ram);
/* close RAM
/* ram_close releases resources associated with RAM.
*
* TODO text
* NOTE struct RAM itself is not released - it has to be explicitly freed by user.
*/
void ram_close(RAM *ram);
......
/* Copyright (C) 2014-2015 Nexedi SA and Contributors.
/* Copyright (C) 2014-2019 Nexedi SA and Contributors.
* Kirill Smelkov <kirr@nexedi.com>
*
* This program is free software: you can Use, Study, Modify and Redistribute
......@@ -95,8 +95,6 @@ void ram_limited_close(RAM *ram0)
// XXX close if owning?
// ram_close(ram->backend);
// TODO free(self) ?
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment