Commit 599c608
gluterd: fix memory leak in glusterd (#4384)
* glusterd: fix memory leaks detected by asan
Memory leaks detected by setting --enable-asan, compile, install
and run gluster cmds, such as gluster v create/start/stop, etc.
Direct leak of 11430 byte(s) in 150 object(s) allocated from:
#0 0x7f59844efbb8 in __interceptor_malloc (/lib64/libasan.so.5+0xefbb8)
#1 0x7f5983aeb96d in __gf_malloc (/lib64/libglusterfs.so.0+0xeb96d)
#2 0x7f59775b569b in glusterd_store_update_volinfo ../../../../libglusterfs/src/glusterfs/mem-pool.h:170
#3 0x7f59775be3b5 in glusterd_store_retrieve_volume glusterd-store.c:3334
#4 0x7f59775bf076 in glusterd_store_retrieve_volumes glusterd-store.c:3571
#5 0x7f59775bfc9e in glusterd_restore glusterd-store.c:4913
#6 0x7f59774ca5a1 (/usr/lib64/glusterfs/8.2/xlator/mgmt/glusterd.so+0xca5a1)
#7 0x7f5983a7cb6b in __xlator_init xlator.c:594
#8 0x7f5983b0c5d0 in glusterfs_graph_init graph.c:422
#9 0x7f5983b0d422 in glusterfs_graph_activate (/lib64/libglusterfs.so.0+0x10d422)
#10 0x5605f2e1eff5 in glusterfs_process_volfp glusterfsd.c:2506
#11 0x5605f2e1f238 in glusterfs_volumes_init glusterfsd.c:2577
#12 0x5605f2e15d8d in main (/usr/sbin/glusterfsd+0x15d8d)
#13 0x7f598103acf2 in __libc_start_main (/lib64/libc.so.6+0x3acf2)
#14 0x5605f2e162cd in _start (/usr/sbin/glusterfsd+0x162cd)
In glusterd_store_update_volinfo, memory will be leaked when the dynamic memory is put
into a dict by calling dict_set_str:
ret = dict_set_str(volinfo->dict, key, gf_strdup(value));
Direct leak of 3351 byte(s) in 30 object(s) allocated from:
#0 0x7f59844efbb8 in __interceptor_malloc (/lib64/libasan.so.5+0xefbb8)
#1 0x7f5983aeb96d in __gf_malloc (/lib64/libglusterfs.so.0+0xeb96d)
#2 0x7f59775541e7 in glusterd_is_path_in_use ../../../../libglusterfs/src/glusterfs/mem-pool.h:170
#3 0x7f59775541e7 in glusterd_check_and_set_brick_xattr glusterd-utils.c:8203
#4 0x7f5977554d7c in glusterd_validate_and_create_brickpath glusterd-utils.c:1549
#5 0x7f5977645fcb in glusterd_op_stage_create_volume glusterd-volume-ops.c:1260
#6 0x7f5977519025 in glusterd_op_stage_validate glusterd-op-sm.c:5787
#7 0x7f5977672555 in gd_stage_op_phase glusterd-syncop.c:1297
#8 0x7f5977676db0 in gd_sync_task_begin glusterd-syncop.c:1951
#9 0x7f59776775dc in glusterd_op_begin_synctask glusterd-syncop.c:2016
#10 0x7f5977642bd6 in __glusterd_handle_create_volume glusterd-volume-ops.c:506
#11 0x7f59774e27b1 in glusterd_big_locked_handler glusterd-handler.c:83
#12 0x7f5983b14cac in synctask_wrap syncop.c:353
#13 0x7f59810240af (/lib64/libc.so.6+0x240af)
During volume creation, glusterd_is_path_in_use will be called to check brick path reuse.
Under normal circumstances, there is no problem, however, when a `force` cmd is given during
volume creation and the futher sys_lsetxattr failed, the memory area previously pointed by
*op_errstr will be leakd, cause:
out:
if (strlen(msg))
*op_errstr = gf_strdup(msg);
Similar leak also exists in posix_cs_set_state:
value = GF_CALLOC(1, xattrsize + 1, gf_posix_mt_char);
...
dict_set_str_sizen(*rsp, GF_CS_OBJECT_REMOTE, value);
Signed-off-by: chenjinhao <[email protected]>
* glusterd: fix memory leaks due to lack of GF_FREE
In glusterd-store.c, there are while loops like:
gf_store_iter_get_next(iter, &key, &value, &op_errno);
while (!ret) {
if (xx_condition) {
do_something();
goto out;
}
GF_FREE(key);
GF_FREE(value);
key = NULL;
value = NULL;
ret = gf_store_iter_get_next(iter, &key, &value, &op_errno);
}
It's ok under normal case, howerver, once the condition does not meet
and the procedure goto 'out', there will be memory leak.
Hence, it is necessary to put a check at 'out'.
Similar leaks will be triggered in glusterd_store_retrieve_peers.
If no peerinfo is found, the procedure will goto the next loop.
It means memory previously allocated for key & value will be
leaked once gf_store_iter_get_next is called again in the next loop.
Signed-off-by: chenjinhao <[email protected]>
---------
Signed-off-by: chenjinhao <[email protected]>
Co-authored-by: chenjinhao <[email protected]>1 parent 00bb343 commit 599c608
File tree
3 files changed
+26
-3
lines changed- xlators
- mgmt/glusterd/src
- storage/posix/src
3 files changed
+26
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2338 | 2338 | | |
2339 | 2339 | | |
2340 | 2340 | | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
2341 | 2345 | | |
2342 | 2346 | | |
2343 | 2347 | | |
| |||
2870 | 2874 | | |
2871 | 2875 | | |
2872 | 2876 | | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
2873 | 2881 | | |
2874 | 2882 | | |
2875 | 2883 | | |
| |||
3015 | 3023 | | |
3016 | 3024 | | |
3017 | 3025 | | |
| 3026 | + | |
| 3027 | + | |
| 3028 | + | |
| 3029 | + | |
3018 | 3030 | | |
3019 | 3031 | | |
3020 | 3032 | | |
| |||
3257 | 3269 | | |
3258 | 3270 | | |
3259 | 3271 | | |
3260 | | - | |
| 3272 | + | |
3261 | 3273 | | |
3262 | 3274 | | |
3263 | 3275 | | |
| |||
4607 | 4619 | | |
4608 | 4620 | | |
4609 | 4621 | | |
| 4622 | + | |
| 4623 | + | |
| 4624 | + | |
| 4625 | + | |
4610 | 4626 | | |
4611 | 4627 | | |
4612 | 4628 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7754 | 7754 | | |
7755 | 7755 | | |
7756 | 7756 | | |
7757 | | - | |
| 7757 | + | |
| 7758 | + | |
| 7759 | + | |
7758 | 7760 | | |
| 7761 | + | |
7759 | 7762 | | |
7760 | 7763 | | |
7761 | 7764 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3288 | 3288 | | |
3289 | 3289 | | |
3290 | 3290 | | |
| 3291 | + | |
| 3292 | + | |
3291 | 3293 | | |
3292 | 3294 | | |
3293 | 3295 | | |
| |||
3311 | 3313 | | |
3312 | 3314 | | |
3313 | 3315 | | |
| 3316 | + | |
| 3317 | + | |
3314 | 3318 | | |
3315 | 3319 | | |
3316 | 3320 | | |
| |||
3325 | 3329 | | |
3326 | 3330 | | |
3327 | 3331 | | |
3328 | | - | |
| 3332 | + | |
3329 | 3333 | | |
3330 | 3334 | | |
3331 | 3335 | | |
| |||
0 commit comments