diff options
author | Vijay Bellur <vbellur@redhat.com> | 2013-02-16 20:10:24 +0530 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2013-03-03 06:19:26 -0800 |
commit | e776deed24645cc52b0fab46d566c91b4163adc1 (patch) | |
tree | dc7b4067639daa93faba74ea8bb2bd0dde0d692f | |
parent | 9a847dac1e73a4994e50273c056e276719b863c9 (diff) |
libglusterfs: Fix memory leaks in fd_lk_insert_and_merge
Change-Id: I666664895fdd7c7199797796819e652557a7ac99
BUG: 834465
Signed-off-by: Vijay Bellur <vbellur@redhat.com>
Reviewed-on: http://review.gluster.org/4529
Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
-rw-r--r-- | libglusterfs/src/fd-lk.c | 8 | ||||
-rw-r--r-- | tests/bugs/bug-834465.c | 61 | ||||
-rwxr-xr-x | tests/bugs/bug-834465.t | 60 | ||||
-rw-r--r-- | tests/volume.rc | 13 |
4 files changed, 138 insertions, 4 deletions
diff --git a/libglusterfs/src/fd-lk.c b/libglusterfs/src/fd-lk.c index fff4aa9966c..caf2bb38e51 100644 --- a/libglusterfs/src/fd-lk.c +++ b/libglusterfs/src/fd-lk.c @@ -380,8 +380,8 @@ _fd_lk_insert_and_merge (fd_lk_ctx_t *lk_ctx, return; } else { sum = _fd_lk_add_locks (entry, lock); - sum->fl_type = entry->fl_type; - sum->user_flock.l_type = entry->fl_type; + sum->fl_type = lock->fl_type; + sum->user_flock.l_type = lock->fl_type; ret = _fd_lk_sub_locks (&v, sum, lock); if (ret) return; @@ -391,6 +391,8 @@ _fd_lk_insert_and_merge (fd_lk_ctx_t *lk_ctx, _fd_lk_delete_lock (lock); _fd_lk_destroy_lock (lock); + _fd_lk_destroy_lock (sum); + for (i = 0; i < 3; i++) { if (!v.locks[i]) continue; @@ -407,7 +409,7 @@ _fd_lk_insert_and_merge (fd_lk_ctx_t *lk_ctx, if (lock->fl_type != F_UNLCK) { _fd_lk_insert_lock (lk_ctx, lock); } else { - _fd_lk_destroy_lock_list (lk_ctx); + _fd_lk_destroy_lock (lock); } } diff --git a/tests/bugs/bug-834465.c b/tests/bugs/bug-834465.c new file mode 100644 index 00000000000..61d3deac077 --- /dev/null +++ b/tests/bugs/bug-834465.c @@ -0,0 +1,61 @@ +#include <sys/file.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +int +main (int argc, char *argv[]) +{ + int fd = -1; + char *filename = NULL; + struct flock lock = {0, }; + int i = 0; + int ret = -1; + + if (argc != 2) { + fprintf (stderr, "Usage: %s <filename> ", argv[0]); + goto out; + } + + filename = argv[1]; + + fd = open (filename, O_RDWR | O_CREAT, 0); + if (fd < 0) { + fprintf (stderr, "open (%s) failed (%s)\n", filename, + strerror (errno)); + goto out; + } + + lock.l_type = F_WRLCK; + lock.l_whence = SEEK_SET; + lock.l_start = 1; + lock.l_len = 1; + + while (i < 100) { + lock.l_type = F_WRLCK; + ret = fcntl (fd, F_SETLK, &lock); + if (ret < 0) { + fprintf (stderr, "fcntl setlk failed (%s)\n", + strerror (errno)); + goto out; + } + + lock.l_type = F_UNLCK; + ret = fcntl (fd, F_SETLK, &lock); + if (ret < 0) { + fprintf (stderr, "fcntl setlk failed (%s)\n", + strerror (errno)); + goto out; + } + + i++; + } + + ret = 0; + +out: + return ret; +} diff --git a/tests/bugs/bug-834465.t b/tests/bugs/bug-834465.t new file mode 100755 index 00000000000..d2e5f47a3aa --- /dev/null +++ b/tests/bugs/bug-834465.t @@ -0,0 +1,60 @@ +#!/bin/bash + +. $(dirname $0)/../include.rc +. $(dirname $0)/../volume.rc + +cleanup; + +TEST glusterd +TEST pidof glusterd +TEST $CLI volume info; + +function volinfo_field() +{ + local vol=$1; + local field=$2; + + $CLI volume info $vol | grep "^$field: " | sed 's/.*: //'; +} + +TEST $CLI volume create $V0 $H0:$B0/brick1 $H0:$B0/brick2; +EXPECT 'Created' volinfo_field $V0 'Status'; + +TEST $CLI volume start $V0; +EXPECT 'Started' volinfo_field $V0 'Status'; + +MOUNTDIR=$M0; +TEST glusterfs --mem-accounting --volfile-server=$H0 --volfile-id=$V0 $MOUNTDIR; + +sdump1=$(generate_mount_statedump $V0); +nalloc1=0 +grep -A2 "fuse - usage-type 85" $sdump1 +if [ $? -eq '0' ] +then + nalloc1=`grep -A2 "fuse - usage-type 85" $sdump1 | grep num_allocs | cut -d '=' -f2` +fi + +function build_tester () +{ + local cfile=$1 + local fname=$(basename "$cfile") + local execname=$(basename $fname ".c") + gcc -g -o $(dirname $cfile)/$execname $cfile +} + +build_tester $(dirname $0)/bug-834465.c + +TEST $(dirname $0)/bug-834465 $M0/testfile + +sdump2=$(generate_mount_statedump $V0); +nalloc2=`grep -A2 "fuse - usage-type 85" $sdump2 | grep num_allocs | cut -d '=' -f2` + +TEST [ $nalloc1 -eq $nalloc2 ]; + +TEST rm -rf $MOUNTDIR/* +TEST rm -rf $(dirname $0)/bug-834465 +cleanup_mount_statedump $V0 + +TEST umount $MOUNTDIR -l + +cleanup; diff --git a/tests/volume.rc b/tests/volume.rc index fe4d8306bc6..9debe2b997f 100644 --- a/tests/volume.rc +++ b/tests/volume.rc @@ -39,11 +39,17 @@ function get_mount_process_pid { ps aux | grep glusterfs | grep -E "volfile-id[ =]/?$vol " | awk '{print $2}' | head -1 } +function cleanup_statedump { + pid=$1 + rm -f $statedumpdir/*$pid.dump.* + #.vimrc friendly comment */ +} + function generate_statedump { local fpath="" pid=$1 #remove old stale statedumps - rm -f $statedumpdir/*$pid.dump.* + cleanup_statedump $pid kill -USR1 $pid #Wait till the statedump is generated sleep 1 @@ -56,6 +62,11 @@ function generate_mount_statedump { generate_statedump $(get_mount_process_pid $vol) } +function cleanup_mount_statedump { + local vol=$1 + cleanup_statedump $(get_mount_process_pid $vol) +} + function _afr_child_up_status { local vol=$1 #brick_id is (brick-num in volume info - 1) |