summaryrefslogtreecommitdiffstats
path: root/tests/bugs/bug-834465.c
diff options
context:
space:
mode:
authorVijay Bellur <vbellur@redhat.com>2013-02-16 20:10:24 +0530
committerVijay Bellur <vbellur@redhat.com>2013-03-03 06:19:26 -0800
commite776deed24645cc52b0fab46d566c91b4163adc1 (patch)
treedc7b4067639daa93faba74ea8bb2bd0dde0d692f /tests/bugs/bug-834465.c
parent9a847dac1e73a4994e50273c056e276719b863c9 (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>
Diffstat (limited to 'tests/bugs/bug-834465.c')
-rw-r--r--tests/bugs/bug-834465.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/bugs/bug-834465.c b/tests/bugs/bug-834465.c
new file mode 100644
index 000000000..61d3deac0
--- /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;
+}