From 2c12ba3d16a3d174500c1a32d8609bf7aec61b1e Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Mon, 21 Sep 2015 08:44:33 +0200 Subject: [PATCH] Various fixes Various fixes for initialisation and packet size allocation --- server/modules/routing/binlog/blr_file.c | 2 +- server/modules/routing/binlog/blr_slave.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/server/modules/routing/binlog/blr_file.c b/server/modules/routing/binlog/blr_file.c index 907c9397e..fa39aca02 100644 --- a/server/modules/routing/binlog/blr_file.c +++ b/server/modules/routing/binlog/blr_file.c @@ -334,7 +334,7 @@ BLFILE *file; return file; } - if ((file = (BLFILE *)malloc(sizeof(BLFILE))) == NULL) + if ((file = (BLFILE *)calloc(1, sizeof(BLFILE))) == NULL) { spinlock_release(&router->fileslock); return NULL; diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index 99d361afc..dd53eed7a 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -463,8 +463,9 @@ int query_len; "%s: Expected DISCONNECT SERVER $server_id", router->service->name))); } else { + int serverid = atoi(word); free(query_text); - return blr_slave_disconnect_server(router, slave, atoi(word)); + return blr_slave_disconnect_server(router, slave, serverid); } } } @@ -1075,7 +1076,7 @@ ROUTER_SLAVE *sptr; sprintf(port, "%d", sptr->port); sprintf(master_id, "%d", router->serverid); sprintf(slave_uuid, "%s", sptr->uuid ? sptr->uuid : ""); - len = 5 + strlen(server_id) + strlen(host) + strlen(port) + len = 4 + strlen(server_id) + strlen(host) + strlen(port) + strlen(master_id) + strlen(slave_uuid) + 5; if ((pkt = gwbuf_alloc(len)) == NULL) return 0; @@ -1907,7 +1908,7 @@ int len, id_len, seqno = 2; strcpy(state, "not found"); id_len = strlen(serverid); - len = 5 + id_len + strlen(state) + 1; + len = 4 + (1 + id_len) + (1 + strlen(state)); if ((pkt = gwbuf_alloc(len)) == NULL) return 0; @@ -1918,7 +1919,7 @@ int len, id_len, seqno = 2; blr_slave_send_eof(router, slave, seqno++); ptr = GWBUF_DATA(pkt); - encode_value(ptr, id_len + 2 + strlen(state), 24); // Add length of data packet + encode_value(ptr, len - 4), 24); // Add length of data packet ptr += 3; *ptr++ = seqno++; // Sequence number in response