Hi,

As it seems we're a bit unlucky at these times. Now I've ran into a
problem in the FreeTDS driver, we're getting heap corruptions inside
freetds, and as it seems the root cause is the DBD freetds driver.

More exactly, dbd_freetds seems to have a single state instance, instead
of allocating a new state for each connection:

typedef struct freedts_type {
    CS_CONTEXT *ctx;
    CS_CONNECTION *conn;
    CS_COMMAND *cmd;
} FREETDSCON;
static FREETDSCON freetds;
^^^^^^^^^^^^^^^^^^^^^^^^^

int dbd_connect(dbi_conn_t * conn)
{
    FREETDSCON *tdscon = &freetds;


This means that if an application uses two DBI contexts at the same
time, those will clash and cause a segfault.

Does anyone know why this limitation was added to the freetds driver?

I'm experimenting with the following patch, but still testing it. I'd
appreciate if you could review it for mistakes I possibly made.

BTW: what is the policy about commented out code in
libdbi/libdbi-drivers source? I personally feel that commented out code
is not good practice, especially if the code in question is commented
out without a note stating the exact reason why it was done. For me it
makes the code harder to read.

-- 
Bazsi
commit 6ec70cf9b3d780a5cceb584ad28ded7a6ec31196
Author: Balazs Scheidler <[EMAIL PROTECTED]>
Date:   Tue Aug 5 10:59:19 2008 +0200

    allow the use of multiple parallel freetds connections

diff --git a/drivers/freetds/dbd_freetds.c b/drivers/freetds/dbd_freetds.c
index 449c313..b869e8b 100644
--- a/drivers/freetds/dbd_freetds.c
+++ b/drivers/freetds/dbd_freetds.c
@@ -56,7 +56,6 @@ typedef struct freedts_type {
     CS_CONNECTION *conn;
     CS_COMMAND *cmd;
 } FREETDSCON;
-static FREETDSCON freetds;
 
 static const dbi_info_t driver_info = {
     "freetds",
@@ -150,12 +149,13 @@ int dbd_initialize(dbi_driver_t * driver)
 
 int dbd_connect(dbi_conn_t * conn)
 {
-
-    FREETDSCON *tdscon = &freetds;
+    FREETDSCON *tdscon;
     CS_RETCODE ret;
 
     char *str;
     unsigned int num;
+    
+    tdscon = malloc(sizeof(FREETDSCON));
 /*
  * Allocate memory for structs
  */
@@ -174,7 +174,7 @@ int dbd_connect(dbi_conn_t * conn)
        /* Deallocate "ctx" struct */
        cs_ctx_drop(tdscon->ctx);
     }
-
+    free(tdscon);
     return -1;
   success_allocate:
     conn->connection = tdscon;
@@ -273,7 +273,7 @@ int dbd_disconnect(dbi_conn_t * conn)
     ct_con_drop(tdscon->conn);
     ct_exit(tdscon->ctx, CS_UNUSED);
     cs_ctx_drop(tdscon->ctx);
-
+    free(tdscon);
     return 0;
 }
 
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Libdbi-drivers-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libdbi-drivers-devel

Reply via email to