summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorDana Robinson <43805+derobins@users.noreply.github.com>2022-07-30 17:29:51 (GMT)
committerGitHub <noreply@github.com>2022-07-30 17:29:51 (GMT)
commit8ed84bf4f07347e6fafe00f5b2a205349d030a63 (patch)
tree2f97365375cddc3f69415e1a7a332fda478588e5 /utils
parentce4c41f89fd1080264dd386e784bf584ed4859d7 (diff)
downloadhdf5-8ed84bf4f07347e6fafe00f5b2a205349d030a63.zip
hdf5-8ed84bf4f07347e6fafe00f5b2a205349d030a63.tar.gz
hdf5-8ed84bf4f07347e6fafe00f5b2a205349d030a63.tar.bz2
Cleanup of mirror VFD test code (#1949)
Diffstat (limited to 'utils')
-rw-r--r--utils/mirror_vfd/mirror_server.c36
-rw-r--r--utils/mirror_vfd/mirror_writer.c37
2 files changed, 50 insertions, 23 deletions
diff --git a/utils/mirror_vfd/mirror_server.c b/utils/mirror_vfd/mirror_server.c
index 95480dc..79c9d80 100644
--- a/utils/mirror_vfd/mirror_server.c
+++ b/utils/mirror_vfd/mirror_server.c
@@ -471,12 +471,13 @@ wait_for_child(int H5_ATTR_UNUSED sig)
static int
handle_requests(struct server_run *run)
{
- int connfd = -1; /**/
- char mybuf[H5FD_MIRROR_XMIT_OPEN_SIZE]; /**/
- ssize_t ret; /* general-purpose error-checking */
- int pid; /* process ID of fork */
- struct sigaction sa;
- int ret_value = 0;
+ int connfd = -1;
+ char *mybuf = NULL;
+ ssize_t ret; /* general-purpose error-checking */
+ int pid; /* process ID of fork */
+ struct sigaction sa;
+ H5FD_mirror_xmit_open_t *xopen = NULL;
+ int ret_value = 0;
if (run == NULL || run->magic != SERVER_RUN_MAGIC) {
mirror_log(NULL, V_ERR, "invalid server_run pointer");
@@ -501,6 +502,15 @@ handle_requests(struct server_run *run)
return 1;
}
+ if (NULL == (mybuf = HDmalloc(H5FD_MIRROR_XMIT_OPEN_SIZE * sizeof(char)))) {
+ mirror_log(NULL, V_ERR, "out of memory");
+ goto error;
+ }
+ if (NULL == (xopen = HDmalloc(sizeof(H5FD_mirror_xmit_open_t)))) {
+ mirror_log(NULL, V_ERR, "out of memory");
+ goto error;
+ }
+
/* Keep listening for attempts to connect.
*/
@@ -518,7 +528,7 @@ handle_requests(struct server_run *run)
/* Read handshake from port connection.
*/
- if ((ret = HDread(connfd, &mybuf, H5FD_MIRROR_XMIT_OPEN_SIZE)) < 0) {
+ if ((ret = HDread(connfd, mybuf, H5FD_MIRROR_XMIT_OPEN_SIZE)) < 0) {
mirror_log(run->loginfo, V_ERR, "read:%d", ret);
goto error;
}
@@ -555,12 +565,11 @@ handle_requests(struct server_run *run)
HDclose(connfd);
} /* end if "CONFIRM" directive */
else if (H5FD_MIRROR_XMIT_OPEN_SIZE == ret) {
- H5FD_mirror_xmit_open_t xopen;
mirror_log(run->loginfo, V_INFO, "probable OPEN xmit received");
- H5FD_mirror_xmit_decode_open(&xopen, (const unsigned char *)mybuf);
- if (FALSE == H5FD_mirror_xmit_is_open(&xopen)) {
+ H5FD_mirror_xmit_decode_open(xopen, (const unsigned char *)mybuf);
+ if (FALSE == H5FD_mirror_xmit_is_open(xopen)) {
mirror_log(run->loginfo, V_WARN, "expected OPEN xmit was malformed");
HDclose(connfd);
continue;
@@ -575,7 +584,7 @@ handle_requests(struct server_run *run)
} /* end if fork error */
else if (pid == 0) { /* child process (writer side of fork) */
mirror_log(run->loginfo, V_INFO, "executing writer");
- if (run_writer(connfd, &xopen) < 0) {
+ if (run_writer(connfd, xopen) < 0) {
HDprintf("can't run writer\n");
}
else {
@@ -605,12 +614,17 @@ done:
HDclose(connfd);
}
+ HDfree(mybuf);
+ HDfree(xopen);
+
return ret_value;
error:
if (connfd >= 0) {
HDclose(connfd);
}
+ HDfree(mybuf);
+ HDfree(xopen);
return -1;
} /* end handle_requests() */
diff --git a/utils/mirror_vfd/mirror_writer.c b/utils/mirror_vfd/mirror_writer.c
index f8d7544..0fec441 100644
--- a/utils/mirror_vfd/mirror_writer.c
+++ b/utils/mirror_vfd/mirror_writer.c
@@ -929,25 +929,33 @@ static int
process_instructions(struct mirror_session *session)
{
struct sock_comm comm;
- char xmit_buf[H5FD_MIRROR_XMIT_BUFFER_MAX]; /* raw bytes */
- H5FD_mirror_xmit_t xmit_recd; /* for decoded xmit header */
+ char *xmit_buf = NULL; /* raw bytes */
+ size_t buf_size;
+ H5FD_mirror_xmit_t xmit_recd; /* for decoded xmit header */
HDassert(session && (session->magic == MW_SESSION_MAGIC));
mirror_log(session->loginfo, V_INFO, "process_instructions()");
+ buf_size = H5FD_MIRROR_XMIT_BUFFER_MAX * sizeof(char);
+
+ if (NULL == (xmit_buf = HDmalloc(buf_size))) {
+ mirror_log(session->loginfo, V_ERR, "out of memory");
+ goto error;
+ }
+
comm.magic = MW_SOCK_COMM_MAGIC;
comm.recd_die = 0; /* Flag for program to terminate */
comm.xmit_recd = &xmit_recd;
comm.raw = xmit_buf;
- comm.raw_size = sizeof(xmit_buf);
+ comm.raw_size = buf_size;
while (1) { /* sill-listening infinite loop */
/* Use convenience structure for raw/decoded info in/out */
if (receive_communique(session, &comm) < 0) {
mirror_log(session->loginfo, V_ERR, "problem reading socket");
- return -1;
+ goto error;
}
if (comm.recd_die) {
@@ -957,42 +965,42 @@ process_instructions(struct mirror_session *session)
switch (xmit_recd.op) {
case H5FD_MIRROR_OP_CLOSE:
if (do_close(session) < 0) {
- return -1;
+ goto error;
}
goto done;
case H5FD_MIRROR_OP_LOCK:
if (do_lock(session, (const unsigned char *)xmit_buf) < 0) {
- return -1;
+ goto error;
}
break;
case H5FD_MIRROR_OP_OPEN:
mirror_log(session->loginfo, V_ERR, "OPEN xmit during session");
reply_error(session, "illegal OPEN xmit during session");
- return -1;
+ goto error;
case H5FD_MIRROR_OP_SET_EOA:
if (do_set_eoa(session, (const unsigned char *)xmit_buf) < 0) {
- return -1;
+ goto error;
}
break;
case H5FD_MIRROR_OP_TRUNCATE:
if (do_truncate(session) < 0) {
- return -1;
+ goto error;
}
break;
case H5FD_MIRROR_OP_UNLOCK:
if (do_unlock(session) < 0) {
- return -1;
+ goto error;
}
break;
case H5FD_MIRROR_OP_WRITE:
if (do_write(session, (const unsigned char *)xmit_buf) < 0) {
- return -1;
+ goto error;
}
break;
default:
mirror_log(session->loginfo, V_ERR, "unrecognized transmission");
reply_error(session, "unrecognized transmission");
- return -1;
+ goto error;
} /* end switch (xmit_recd.op) */
} /* end while still listening */
@@ -1000,7 +1008,12 @@ process_instructions(struct mirror_session *session)
done:
comm.magic = 0; /* invalidate structure, on principle */
xmit_recd.magic = 0; /* invalidate structure, on principle */
+ HDfree(xmit_buf);
return 0;
+
+error:
+ HDfree(xmit_buf);
+ return -1;
} /* end process_instructions() */
/* ---------------------------------------------------------------------------