aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-03-01 15:00:05 -0500
committerBrian Cully <bjc@kublai.com>2008-03-01 15:00:05 -0500
commitd7751a3a4adf0bde22278bf8828664a38d08d53b (patch)
tree780262c63c6df28ae923362d63f1048c43f4a25b /src
parentda94ebf8245faa0c208709c7effbbb6e4a149630 (diff)
downloadmysqlerl-d7751a3a4adf0bde22278bf8828664a38d08d53b.tar.gz
mysqlerl-d7751a3a4adf0bde22278bf8828664a38d08d53b.zip
Clean up partial messages.
Null terminate message buffers.
Diffstat (limited to 'src')
-rw-r--r--src/mysqlerl.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/mysqlerl.c b/src/mysqlerl.c
index 1731af2..dc1e868 100644
--- a/src/mysqlerl.c
+++ b/src/mysqlerl.c
@@ -112,6 +112,7 @@ read_msg()
if (msg == NULL) {
logmsg("ERROR: Couldn't allocate message for reading: %s.\n",
strerror(errno));
+
exit(2);
}
@@ -119,22 +120,29 @@ read_msg()
if (restartable_read((char *)&len, sizeof(len)) == -1) {
logmsg("ERROR: couldn't read %d byte message prefix: %s.",
sizeof(len), strerror(errno));
+
+ free(msg);
exit(2);
}
len = ntohl(len);
- msg->buf = malloc(len);
+ msg->buf = malloc(len + 1);
if (msg->buf == NULL) {
logmsg("ERROR: Couldn't malloc %d bytes: %s.", len,
strerror(errno));
+
+ free(msg);
exit(2);
}
- memset(msg->buf, 0, len);
+ msg->buf[len] = '\0';
logmsg("DEBUG: reading message body (len: %d).", len);
if (restartable_read(msg->buf, len) == -1) {
logmsg("ERROR: couldn't read %d byte message: %s.",
len, strerror(errno));
+
+ free(msg->buf);
+ free(msg);
exit(2);
}