Quoting Alex Dubov <[EMAIL PROTECTED]>:

The comment also says that it is possible to do
something like this for mysql <  5.0.13:
-----
MYSQL *db;
....
db = mysql_real_connect(db, ...)
db->reconnect = 1;
...
-----

Right. I don't think we need to worry about these old versions anyway, given that they may have security issues, so users should be going forward to 5.0.21 and better (if they're on 5.0).

I think I'll just move the option to after connect.

In light of this - new patch. Also fixes a small
memory leak, which may happen if mysql_real_connect
fails, but mysql_init succeeds.

Yes. However, there is also a whole bunch of apr_pstrndup's going on after init, which will eat a small chunk of memory as well. Callers can always create their own little pools and drop them if the open is not successful to avoid this.

However, for this to work, we should return NULL from _open, just like you did in your other patch. So, I was thinking this:

-------------------------------------------------------------------
Index: apr_dbd_mysql.c
===================================================================
--- apr_dbd_mysql.c     (revision 38)
+++ apr_dbd_mysql.c     (working copy)
@@ -626,13 +626,18 @@
         port = atoi(fields[4].value);
     }

-#if MYSQL_VERSION_ID >= 50013
-    mysql_options(sql->conn, MYSQL_OPT_RECONNECT, &do_reconnect);
-#endif
     sql->conn = mysql_real_connect(sql->conn, fields[0].value,
                                    fields[1].value, fields[2].value,
                                    fields[3].value, port,
                                    fields[5].value, CLIENT_FOUND_ROWS);
+
+    if(sql->conn == NULL)
+        return NULL;
+
+#if MYSQL_VERSION_ID >= 50013
+    mysql_options(sql->conn, MYSQL_OPT_RECONNECT, &do_reconnect);
+#endif
+
     return sql;
 }
 static apr_status_t dbd_mysql_close(apr_dbd_t *handle)
-------------------------------------------------------------------

--
Bojan

Reply via email to