From 46c4fefb001da04e1725bfc9938575fabba9a705 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 22 Feb 2015 22:29:30 +0200 Subject: [PATCH] Fixes to coverity defects 87601 87557 87548 87547 87546 87545 87544 87536 87535 87529 87528 --- query_classifier/query_classifier.cc | 3 ++- server/core/gateway.c | 3 ++- server/core/service.c | 2 +- server/modules/routing/binlog/blr.c | 2 +- server/modules/routing/binlog/blr_file.c | 2 +- server/modules/routing/binlog/blr_master.c | 10 +++++++--- server/modules/routing/binlog/blr_slave.c | 2 +- server/modules/routing/readwritesplit/readwritesplit.c | 2 +- 8 files changed, 16 insertions(+), 10 deletions(-) diff --git a/query_classifier/query_classifier.cc b/query_classifier/query_classifier.cc index f8da45567..5bc793004 100644 --- a/query_classifier/query_classifier.cc +++ b/query_classifier/query_classifier.cc @@ -1219,7 +1219,8 @@ inline void add_str(char** buf, int* buflen, int* bufsize, char* str) if(*buf) strcat(*buf," "); } - strcat(*buf,str); + if(*buf) + strcat(*buf,str); *buflen += isize; } diff --git a/server/core/gateway.c b/server/core/gateway.c index d7ade597a..1221cee3b 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -632,7 +632,8 @@ static bool resolve_maxscale_homedir( * 3. if /etc/MaxScale/MaxScale.cnf didn't exist or wasn't accessible, home * isn't specified. Thus, try to access $PWD/MaxScale.cnf . */ - tmp = strndup(getenv("PWD"), PATH_MAX); + char *pwd = getenv("PWD"); + tmp = strndup(pwd ? pwd : "PWD_NOT_SET", PATH_MAX); tmp2 = get_expanded_pathname(p_home_dir, tmp, default_cnf_fname); free(tmp2); /*< full path isn't needed so simply free it */ diff --git a/server/core/service.c b/server/core/service.c index 167f8a4e7..9c5bdba23 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -250,7 +250,7 @@ GWPROTOCOL *funcs; else { /* Save authentication data to file cache */ - char *ptr, path[4096]; + char *ptr, path[4097]; int mkdir_rval = 0; strcpy(path, "/usr/local/skysql/MaxScale"); if ((ptr = getenv("MAXSCALE_HOME")) != NULL) diff --git a/server/modules/routing/binlog/blr.c b/server/modules/routing/binlog/blr.c index 9cb2fd106..2ba89689f 100644 --- a/server/modules/routing/binlog/blr.c +++ b/server/modules/routing/binlog/blr.c @@ -432,7 +432,7 @@ unsigned char *defuuid; * Now start the replication from the master to MaxScale */ blr_start_master(inst); - + free(name); return (ROUTER *)inst; } diff --git a/server/modules/routing/binlog/blr_file.c b/server/modules/routing/binlog/blr_file.c index 358dc002c..a3b3b7054 100644 --- a/server/modules/routing/binlog/blr_file.c +++ b/server/modules/routing/binlog/blr_file.c @@ -668,7 +668,7 @@ GWBUF * blr_cache_read_response(ROUTER_INSTANCE *router, char *response) { struct stat statb; -char path[4096], *ptr; +char path[4097], *ptr; int fd; GWBUF *buf; diff --git a/server/modules/routing/binlog/blr_master.c b/server/modules/routing/binlog/blr_master.c index aaeba13b6..83c95ddf9 100644 --- a/server/modules/routing/binlog/blr_master.c +++ b/server/modules/routing/binlog/blr_master.c @@ -142,6 +142,7 @@ GWBUF *buf; sprintf(name, "%s Master", router->service->name); hktask_oneshot(name, blr_start_master, router, BLR_MASTER_BACKOFF_TIME * router->retry_backoff++); + free(name); } if (router->retry_backoff > BLR_MAX_BACKOFF) router->retry_backoff = BLR_MAX_BACKOFF; @@ -203,11 +204,12 @@ GWBUF *ptr; router->master_state = BLRM_UNCONNECTED; if ((name = malloc(strlen(router->service->name) - + strlen(" Master")+1)) != NULL); + + strlen(" Master")+1)) != NULL) { sprintf(name, "%s Master", router->service->name); hktask_oneshot(name, blr_start_master, router, BLR_MASTER_BACKOFF_TIME * router->retry_backoff++); + free(name); } if (router->retry_backoff > BLR_MAX_BACKOFF) router->retry_backoff = BLR_MAX_BACKOFF; @@ -283,10 +285,11 @@ blr_master_delayed_connect(ROUTER_INSTANCE *router) char *name; if ((name = malloc(strlen(router->service->name) - + strlen(" Master Recovery")+1)) != NULL); + + strlen(" Master Recovery")+1)) != NULL) { sprintf(name, "%s Master Recovery", router->service->name); hktask_oneshot(name, blr_start_master, router, 60); + free(name); } } @@ -407,6 +410,7 @@ char query[128]; } router->master_state = BLRM_HBPERIOD; router->master->func.write(router->master, buf); + free(val); break; } case BLRM_HBPERIOD: @@ -701,7 +705,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt) { uint8_t *msg = NULL, *ptr, *pdata; REP_HEADER hdr; -unsigned int len, reslen; +unsigned int len = 0, reslen; unsigned int pkt_length; int no_residual = 1; int preslen = -1; diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index 4aafd41fd..21260fcb2 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -1371,7 +1371,7 @@ blr_slave_catchup(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, bool large) GWBUF *head, *record; REP_HEADER hdr; int written, rval = 1, burst; -int rotating; +int rotating = 0; unsigned long burst_size; uint8_t *ptr; diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index eed1fcf65..d5ffed838 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -3758,7 +3758,7 @@ static GWBUF* sescmd_cursor_process_replies( dcb_close(bref->bref_dcb); *reconnect = true; if(replybuf) - gwbuf_free(replybuf); + gwbuf_consume(replybuf,gwbuf_length(replybuf)); } } /** This is a response from the master and it is the "right" one.