summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2012-01-16 04:50:53 -0800
committerGerrit Code Review <root@dev.gluster.com>2012-01-16 04:50:53 -0800
commitbb479f34dcb22ea20b8ce307e8831d6e8e6751ea (patch)
tree6c799d6a4d0a81a38153b85a7cfff529a711caba
parent7cb83f7754bf2483aa29d66c086c82f52878fe47 (diff)
parent15472c449d9da05fc1a4277d82c6c2126ae4b81d (diff)
Merge "ping_pong: allocate the memory from heap instead of using the stack address"
-rw-r--r--c_pgms/ping_pong.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/c_pgms/ping_pong.c b/c_pgms/ping_pong.c
index 7881266..90141cf 100644
--- a/c_pgms/ping_pong.c
+++ b/c_pgms/ping_pong.c
@@ -193,7 +193,7 @@ int main(int argc, char *argv[])
char *fname;
int fd, num_locks;
int c;
- file_info_t info_file;
+ file_info_t *info_file = NULL;
pthread_t thread;
int tid = -1;
int zzzz = 600;
@@ -247,10 +247,16 @@ int main(int argc, char *argv[])
fd = open(fname, O_CREAT|O_RDWR, 0600);
if (fd == -1) exit(1);
- info_file.fd = fd;
- info_file.num_locks = num_locks;
+ info_file = calloc (1, sizeof (*info_file));
+ if (!info_file) {
+ ret = -1;
+ goto out;
+ }
+
+ info_file->fd = fd;
+ info_file->num_locks = num_locks;
- tid = pthread_create (&thread, NULL, (void *)ping_pong, (void *)&info_file);
+ tid = pthread_create (&thread, NULL, (void *)ping_pong, (void *)info_file);
if (zzzz == 0) {
printf ("running indefinitely\n");