Changeset: 831685e763a4 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=831685e763a4
Modified Files:
tools/merovingian/client/monetdb.c
tools/merovingian/daemon/argvcmds.c
tools/merovingian/daemon/connections.c
tools/merovingian/daemon/discoveryrunner.c
tools/merovingian/daemon/forkmserver.c
tools/merovingian/daemon/merovingian.c
tools/merovingian/daemon/multiplex-funnel.c
tools/merovingian/daemon/peering.c
tools/merovingian/daemon/proxy.c
tools/merovingian/utils/utils.c
Branch: Oct2014
Log Message:
Fixed various issues found by Coverity.
diffs (truncated from 597 to 300 lines):
diff --git a/tools/merovingian/client/monetdb.c
b/tools/merovingian/client/monetdb.c
--- a/tools/merovingian/client/monetdb.c
+++ b/tools/merovingian/client/monetdb.c
@@ -198,7 +198,7 @@ MEROgetStatus(sabdb **ret, char *databas
sabdb *w = NULL;
size_t swlen = 50;
size_t swpos = 0;
- sabdb **sw = malloc(sizeof(sabdb *) * swlen);
+ sabdb **sw;
char *p;
char *buf;
char *e;
@@ -211,11 +211,13 @@ MEROgetStatus(sabdb **ret, char *databas
if (e != NULL)
return(e);
+ sw = malloc(sizeof(sabdb *) * swlen);
orig = NULL;
if ((p = strtok(buf, "\n")) != NULL) {
if (strcmp(p, "OK") != 0) {
p = strdup(p);
free(buf);
+ free(sw);
return(p);
}
for (swpos = 0; (p = strtok(NULL, "\n")) != NULL; swpos++) {
@@ -345,6 +347,7 @@ printStatus(sabdb *stats, int mode, int
printf(" ");
}
printf(" %-*s\n", uriwidth, uri);
+ free(uri);
} else if (mode == 2) {
/* long mode */
char *state;
@@ -1299,6 +1302,7 @@ command_get(int argc, char *argv[])
/* avoid work when there are no results */
if (orig == NULL) {
free(props);
+ free(defprops);
return;
}
@@ -1434,6 +1438,7 @@ command_get(int argc, char *argv[])
free(value);
msab_freeStatus(&orig);
free(props);
+ free(defprops);
}
static void
diff --git a/tools/merovingian/daemon/argvcmds.c
b/tools/merovingian/daemon/argvcmds.c
--- a/tools/merovingian/daemon/argvcmds.c
+++ b/tools/merovingian/daemon/argvcmds.c
@@ -197,10 +197,11 @@ command_get(confkeyval *ckv, int argc, c
FILE *pf;
char *pfile = getConfVal(ckv, "pidfile");
- if (pfile != NULL && (pf = fopen(pfile, "r")) != NULL &&
- fgets(buf, sizeof(buf), pf) != NULL)
- {
- meropid = atoi(buf);
+ if (pfile != NULL && (pf = fopen(pfile, "r")) != NULL) {
+ if (fgets(buf, sizeof(buf), pf) != NULL) {
+ meropid = atoi(buf);
+ }
+ fclose(pf);
}
} else {
if (ret >= 0) {
@@ -410,6 +411,7 @@ command_set(confkeyval *ckv, int argc, c
if (dohash == 1) {
p = mcrypt_BackendSum(p, strlen(p));
snprintf(h, sizeof(h), "{%s}%s", MONETDB5_PASSWDHASH,
p);
+ free(p);
p = h;
}
}
@@ -433,20 +435,18 @@ command_set(confkeyval *ckv, int argc, c
return(1);
}
- if ((pfile = fopen(property, "r")) != NULL &&
- fgets(buf, sizeof(buf), pfile) != NULL)
- {
- meropid = atoi(buf);
- if (meropid != 0) {
- if (kill(meropid, SIGHUP) == -1) {
- fprintf(stderr, "sending SIGHUP to monetdbd[%d]
failed: %s\n",
- (int)meropid, strerror(errno));
- return(1);
- }
+ if ((pfile = fopen(property, "r")) != NULL) {
+ if (fgets(buf, sizeof(buf), pfile) != NULL &&
+ (meropid = atoi(buf)) != 0 &&
+ kill(meropid, SIGHUP) == -1)
+ {
+ fprintf(stderr, "sending SIGHUP to monetdbd[%d] failed:
%s\n",
+ (int)meropid, strerror(errno));
+ fclose(pfile);
+ return(1);
}
+ fclose(pfile);
}
- if (pfile != NULL)
- fclose(pfile);
return(0);
}
@@ -492,6 +492,7 @@ command_stop(confkeyval *ckv, int argc,
if (fgets(buf, sizeof(buf), pfile) == NULL) {
fprintf(stderr, "unable to read from %s: %s\n",
pidfilename, strerror(errno));
+ fclose(pfile);
return(1);
}
fclose(pfile);
diff --git a/tools/merovingian/daemon/connections.c
b/tools/merovingian/daemon/connections.c
--- a/tools/merovingian/daemon/connections.c
+++ b/tools/merovingian/daemon/connections.c
@@ -74,13 +74,16 @@ openConnectionTCP(int *ret, unsigned sho
server.sin_port = htons((unsigned short) ((port) & 0xFFFF));
if (bind(sock, (SOCKPTR) &server, length) < 0) {
+ closesocket(sock);
return(newErr("binding to stream socket port %hu failed: %s",
port, strerror(errno)));
}
- if (getsockname(sock, (SOCKPTR) &server, &length) < 0)
+ if (getsockname(sock, (SOCKPTR) &server, &length) < 0) {
+ closesocket(sock);
return(newErr("failed getting socket name: %s",
strerror(errno)));
+ }
hoste = gethostbyaddr(&server.sin_addr.s_addr, 4, server.sin_family);
if (hoste == NULL) {
snprintf(hostip, sizeof(hostip), "%u.%u.%u.%u",
@@ -134,7 +137,7 @@ openConnectionUDP(int *ret, unsigned sho
if (bind(sock, rp->ai_addr, rp->ai_addrlen) == 0)
break; /* working */
- close(sock);
+ closesocket(sock);
}
if (rp == NULL) {
diff --git a/tools/merovingian/daemon/discoveryrunner.c
b/tools/merovingian/daemon/discoveryrunner.c
--- a/tools/merovingian/daemon/discoveryrunner.c
+++ b/tools/merovingian/daemon/discoveryrunner.c
@@ -248,13 +248,15 @@ static disc_message_tap _mero_disc_msg_t
void
registerMessageTap(int fd)
{
- disc_message_tap h = _mero_disc_msg_taps;
+ disc_message_tap h;
/* make sure we never block in the main loop below because we can't
* write to the pipe */
fcntl(fd, F_SETFD, O_NONBLOCK);
pthread_mutex_lock(&_mero_remotedb_lock);
+ h = _mero_disc_msg_taps;
if (h == NULL) {
h = malloc(sizeof(struct _disc_message_tap));
+ _mero_disc_msg_taps = h;
} else {
for (; h->next != NULL; h = h->next)
;
@@ -268,9 +270,9 @@ registerMessageTap(int fd)
void
unregisterMessageTap(int fd)
{
- disc_message_tap h = _mero_disc_msg_taps;
- disc_message_tap lasth;
+ disc_message_tap h, lasth;
pthread_mutex_lock(&_mero_remotedb_lock);
+ h = _mero_disc_msg_taps;
for (lasth = NULL; h != NULL; lasth = h, h = h->next) {
if (h->fd == fd) {
if (lasth == NULL) {
@@ -510,6 +512,7 @@ discoveryRunner(void *d)
Mfprintf(_mero_discerr, "msab_getStatus error: %s, "
"discovery services disabled\n", e);
free(e);
+ free(ckv);
return;
}
diff --git a/tools/merovingian/daemon/forkmserver.c
b/tools/merovingian/daemon/forkmserver.c
--- a/tools/merovingian/daemon/forkmserver.c
+++ b/tools/merovingian/daemon/forkmserver.c
@@ -284,7 +284,11 @@ forkMserver(char *database, sabdb** stat
int c = 0;
unsigned int mport;
- msab_getDBfarm(&sabdbfarm);
+ er = msab_getDBfarm(&sabdbfarm);
+ if (er != NULL) {
+ Mfprintf(stderr, "unexpected error: %s\n", er);
+ exit(1);
+ }
mydoproxy = strcmp(getConfVal(_mero_props, "forward"), "proxy")
== 0;
@@ -406,139 +410,141 @@ forkMserver(char *database, sabdb** stat
/* if the exec returns, it is because of a failure */
Mfprintf(stderr, "executing failed: %s\n", strerror(errno));
exit(1);
- } else if (pid > 0) {
+ } else {
/* don't need this, child did */
freeConfFile(ckv);
free(ckv);
- /* make sure no entries are shot while adding and that we
- * deliver a consistent state */
- pthread_mutex_lock(&_mero_topdp_lock);
+ if (pid > 0) {
+ /* make sure no entries are shot while adding and that
we
+ * deliver a consistent state */
+ pthread_mutex_lock(&_mero_topdp_lock);
- /* parent: fine, let's add the pipes for this child */
- dp = _mero_topdp;
- while (dp->next != NULL)
- dp = dp->next;
- dp = dp->next = malloc(sizeof(struct _dpair));
- dp->out = pfdo[0];
- close(pfdo[1]);
- dp->err = pfde[0];
- close(pfde[1]);
- dp->next = NULL;
- dp->type = MERODB;
- dp->pid = pid;
- dp->dbname = strdup(database);
+ /* parent: fine, let's add the pipes for this child */
+ dp = _mero_topdp;
+ while (dp->next != NULL)
+ dp = dp->next;
+ dp = dp->next = malloc(sizeof(struct _dpair));
+ dp->out = pfdo[0];
+ close(pfdo[1]);
+ dp->err = pfde[0];
+ close(pfde[1]);
+ dp->next = NULL;
+ dp->type = MERODB;
+ dp->pid = pid;
+ dp->dbname = strdup(database);
- pthread_mutex_unlock(&_mero_topdp_lock);
-
- /* wait for the child to finish starting, at some point we
- * decided that we should wait indefinitely here because if the
- * mserver needs time to start up, we shouldn't interrupt it,
- * and if it hangs, we're just doomed, with the drawback that we
- * completely kill the functionality of monetdbd too */
- do {
- /* give the database a break */
- sleep_ms(500);
-
- /* in the meanwhile, if the server has stopped, it will
- * have been removed from the dpair list, so check if
- * it's still there. */
- pthread_mutex_lock(&_mero_topdp_lock);
- dp = _mero_topdp;
- while (dp != NULL && dp->pid != pid)
- dp = dp->next;
pthread_mutex_unlock(&_mero_topdp_lock);
- /* stats cannot be NULL, as we don't allow starting non
- * existing databases, note that we need to run this
loop at
- * least once not to leak */
- msab_freeStatus(stats);
- er = msab_getStatus(stats, database);
- if (er != NULL) {
- /* since the client mserver lives its own life
anyway,
- * it's not really a problem we exit here */
- err e = newErr("%s", er);
- free(er);
- pthread_mutex_unlock(&fork_lock);
- return(e);
- }
+ /* wait for the child to finish starting, at some point
we
+ * decided that we should wait indefinitely here
because if the
+ * mserver needs time to start up, we shouldn't
interrupt it,
+ * and if it hangs, we're just doomed, with the
drawback that we
+ * completely kill the functionality of monetdbd too */
+ do {
+ /* give the database a break */
+ sleep_ms(500);
- /* server doesn't run, no need to wait any longer */
- if (dp == NULL)
- break;
- } while ((*stats)->state != SABdbRunning);
+ /* in the meanwhile, if the server has stopped,
it will
+ * have been removed from the dpair list, so
check if
+ * it's still there. */
+ pthread_mutex_lock(&_mero_topdp_lock);
+ dp = _mero_topdp;
+ while (dp != NULL && dp->pid != pid)
+ dp = dp->next;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list