[freetds] Bug in dblib CHECK_CONN macro?

Joshua Lang joshua.h.lang at gmail.com
Fri Dec 18 15:06:49 EST 2015

It seems that once the TDS socket on a dblib connection becomes invalid,
the error handling no long er references the connection, even though it
seems as though it should? Perhaps I'm missing something? This is causing
subsequent uses of the DBPROCESS pointer to fail (as they should), but the
resulting error is not correctly associated with the DBPROCESS.

See below for a patch. Note that dbproc is passed instead of NULL to

diff --git a/include/dblib.h b/include/dblib.h
index e03ccaa..019c99d 100644
--- a/include/dblib.h
+++ b/include/dblib.h
@@ -199,7 +199,7 @@ extern EHANDLEFUNC _dblib_err_handler;
 #define DBPERROR_RETURN(x, msg)        if (x) { dbperror(dbproc, (msg),
0); return FAIL; }
 #define DBPERROR_RETURN3(x, msg, a, b, c)      if (x) { dbperror(dbproc,
(msg), 0, a, b, c); return FAIL; }
 #define CHECK_CONN(ret) do { CHECK_PARAMETER(dbproc, SYBENULL, (ret)); \
-       if (IS_TDSDEAD(dbproc->tds_socket)) { dbperror(NULL, SYBEDDNE, 0);
return (ret); } } while(0)
+       if (IS_TDSDEAD(dbproc->tds_socket)) { dbperror(dbproc, SYBEDDNE,
0); return (ret); } } while(0)

 #ifdef __cplusplus

More information about the FreeTDS mailing list