Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory leak detected in glusterd #4383

Open
chen1195585098 opened this issue Jun 25, 2024 · 0 comments · May be fixed by #4384
Open

memory leak detected in glusterd #4383

chen1195585098 opened this issue Jun 25, 2024 · 0 comments · May be fixed by #4384

Comments

@chen1195585098
Copy link
Contributor

Description of problem:
There are potential memory leaks in glusterd. Some of the detect logs are as follows:

    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)
    
    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)

The exact command to reproduce the issue:
set --enable-asan, then compile,install glusterfs and run gluster cmds, such as volume create/start/stop/add-brick/remove-brick, etc.

chen1195585098 pushed a commit to chen1195585098/glusterfs that referenced this issue Jun 25, 2024
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 in 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 allocated for key & value will be leaked once
gf_store_iter_get_next is called again in the next loop.

This patch fixes above mentioned memory leaks, and that detected by
asan.

Direct leak of 11430 byte(s) in 150 object(s) allocated from:
    #0 0x7f59844efbb8 in __interceptor_malloc (/lib64/libasan.so.5+0xefbb8)
    gluster#1 0x7f5983aeb96d in __gf_malloc (/lib64/libglusterfs.so.0+0xeb96d)
    gluster#2 0x7f59775b569b in glusterd_store_update_volinfo ../../../../libglusterfs/src/glusterfs/mem-pool.h:170
    gluster#3 0x7f59775be3b5 in glusterd_store_retrieve_volume glusterd-store.c:3334
    gluster#4 0x7f59775bf076 in glusterd_store_retrieve_volumes glusterd-store.c:3571
    gluster#5 0x7f59775bfc9e in glusterd_restore glusterd-store.c:4913
    gluster#6 0x7f59774ca5a1  (/usr/lib64/glusterfs/8.2/xlator/mgmt/glusterd.so+0xca5a1)
    gluster#7 0x7f5983a7cb6b in __xlator_init xlator.c:594
    gluster#8 0x7f5983b0c5d0 in glusterfs_graph_init graph.c:422
    gluster#9 0x7f5983b0d422 in glusterfs_graph_activate (/lib64/libglusterfs.so.0+0x10d422)
    gluster#10 0x5605f2e1eff5 in glusterfs_process_volfp glusterfsd.c:2506
    gluster#11 0x5605f2e1f238 in glusterfs_volumes_init glusterfsd.c:2577
    gluster#12 0x5605f2e15d8d in main (/usr/sbin/glusterfsd+0x15d8d)
    gluster#13 0x7f598103acf2 in __libc_start_main (/lib64/libc.so.6+0x3acf2)
    gluster#14 0x5605f2e162cd in _start (/usr/sbin/glusterfsd+0x162cd)

Direct leak of 3351 byte(s) in 30 object(s) allocated from:
    #0 0x7f59844efbb8 in __interceptor_malloc (/lib64/libasan.so.5+0xefbb8)
    gluster#1 0x7f5983aeb96d in __gf_malloc (/lib64/libglusterfs.so.0+0xeb96d)
    gluster#2 0x7f59775541e7 in glusterd_is_path_in_use ../../../../libglusterfs/src/glusterfs/mem-pool.h:170
    gluster#3 0x7f59775541e7 in glusterd_check_and_set_brick_xattr glusterd-utils.c:8203
    gluster#4 0x7f5977554d7c in glusterd_validate_and_create_brickpath glusterd-utils.c:1549
    gluster#5 0x7f5977645fcb in glusterd_op_stage_create_volume glusterd-volume-ops.c:1260
    gluster#6 0x7f5977519025 in glusterd_op_stage_validate glusterd-op-sm.c:5787
    gluster#7 0x7f5977672555 in gd_stage_op_phase glusterd-syncop.c:1297
    gluster#8 0x7f5977676db0 in gd_sync_task_begin glusterd-syncop.c:1951
    gluster#9 0x7f59776775dc in glusterd_op_begin_synctask glusterd-syncop.c:2016
    gluster#10 0x7f5977642bd6 in __glusterd_handle_create_volume glusterd-volume-ops.c:506
    gluster#11 0x7f59774e27b1 in glusterd_big_locked_handler glusterd-handler.c:83
    gluster#12 0x7f5983b14cac in synctask_wrap syncop.c:353
    gluster#13 0x7f59810240af  (/lib64/libc.so.6+0x240af)

Fixes: gluster#4383
Signed-off-by: chenjinhao <[email protected]>
@chen1195585098 chen1195585098 linked a pull request Jun 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant