Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions librdmacm/examples/rcopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,10 @@ static int server_listen(void)
return ret;
}

static char *path = NULL;

static int server_open(int rs, struct msg_hdr *msg)
{
char *path = NULL;
int ret, len;

printf("opening: ");
Expand Down Expand Up @@ -264,8 +265,6 @@ static int server_open(int rs, struct msg_hdr *msg)

ret = 0;
out:
if (path)
free(path);

msg_send_resp(rs, msg, ret);
return ret;
Expand All @@ -286,6 +285,10 @@ static void server_close(int rs, struct msg_hdr *msg)
close(fd);
fd = 0;
}

free(path);
path = NULL;

printf("done\n");
}

Expand All @@ -312,9 +315,13 @@ static int server_write(int rs, struct msg_hdr *msg)
if (ret != sizeof bytes)
goto out;

ret = ftruncate(fd, bytes);
if (ret)
ret = posix_fallocate(fd, 0, bytes);
if (ret) {
printf("...error allocating file\n");
close(fd);
unlink(path);
goto out;
}

file_addr = mmap(NULL, bytes, PROT_WRITE, MAP_SHARED, fd, 0);
if (file_addr == (void *) -1) {
Expand Down