summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2013-07-16 11:22:54 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-07-16 11:22:54 (GMT)
commit351364f283f3223f29090068069a127aef572cbf (patch) (side-by-side diff)
tree9fd33448ff931d0b50179eb2f8e67ee0b08bde21
parent4d1f5fc9ea196282a8c0ed81bf7ec43bb41e1396 (diff)
downloadvmod-dbrw-351364f283f3223f29090068069a127aef572cbf.tar.gz
vmod-dbrw-351364f283f3223f29090068069a127aef572cbf.tar.bz2
Bugfixes.
* src/mysql.c (s_mysql_connect): If unable to connect, issue an error message. * src/vmod_dbrw.c (expand_backref): Rewrite memory management part.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/mysql.c4
-rw-r--r--src/vmod_dbrw.c30
2 files changed, 16 insertions, 18 deletions
diff --git a/src/mysql.c b/src/mysql.c
index 98cb2f7..9805887 100644
--- a/src/mysql.c
+++ b/src/mysql.c
@@ -136,8 +136,10 @@ s_mysql_connect(struct dbrw_connection *conn)
findparam(conn->conf->param, "database"),
port,
socket_name,
- CLIENT_MULTI_RESULTS))
+ CLIENT_MULTI_RESULTS)) {
+ dbrw_error("cannot connect: %s", mysql_error(mp->mysql));
return -1;
+ }
debug(conn->conf, 1, ("connected to database"));
return 0;
diff --git a/src/vmod_dbrw.c b/src/vmod_dbrw.c
index 8afaf04..2895ea5 100644
--- a/src/vmod_dbrw.c
+++ b/src/vmod_dbrw.c
@@ -265,12 +265,10 @@ expand_backref(struct sess *sp, const char *str, const char *val,
size_t matchcount, regmatch_t *matches, char *qry)
{
unsigned u;
- char *b, *e, *p;
+ char *b, *p;
u = WS_Reserve(sp->wrk->ws, 0);
- e = b = sp->wrk->ws->f;
- e += u;
- p = b;
+ p = b = sp->wrk->ws->f;
while (*val) {
if (u == 0) {
@@ -310,17 +308,9 @@ expand_backref(struct sess *sp, const char *str, const char *val,
u--;
}
- if (u == 0) {
- WS_Release(sp->wrk->ws, 0);
- return NULL;
- }
-
- *p = 0;
- u--;
-
if (qry) {
- size_t len = strlen(qry) + 1;
- if (len >= u) {
+ size_t len = strlen(qry);
+ if (len + 1 >= u) {
WS_Release(sp->wrk->ws, 0);
return NULL;
}
@@ -329,11 +319,17 @@ expand_backref(struct sess *sp, const char *str, const char *val,
else
*p++ = '?';
memcpy(p, qry, len);
+ p += len;
u -= len;
- }
+ }
+
+ if (u == 0) {
+ WS_Release(sp->wrk->ws, 0);
+ return NULL;
+ }
+ *p = 0;
- if (u)
- WS_Release(sp->wrk->ws, u);
+ WS_ReleaseP(sp->wrk->ws, p);
return b;
}

Return to:

Send suggestions and report system problems to the System administrator.