Uploaded image for project: 'MariaDB Connector/C'
  1. MariaDB Connector/C
  2. CONC-118

Options get lost and Memory-leak when reconnecting

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 2.0.0
    • 2.1
    • None
    • None
    • Linux 32/64 bit

    Description

      Hi Georg,

      thanks for fixing the bug CONC-117. But there are still a few bugs which need to be fixed in function "mysql_reconnect" from file "libmariadb.c" :

      1. Original options from client would get lost if reconnecting fails, because of the bzero() before function "mysql_real_connect()"

      2. The free_me flag in original mysql object is set to 0, which would lead to memory leak. You should store the old value and set it back after cloning from tmp_mysql object.

      I wrote the patch with some comment. More details and descriptions can be found in uploaded file.

      Attachments

        Activity

          georg Georg Richter added a comment -

          fixed in rev. 192

          georg Georg Richter added a comment - fixed in rev. 192
          tianhongxu Tianhong added a comment -

          Hey Georg,

          thanks for the support. I read the new code and thought that the first issue is still there: "Original options from client would get lost if reconnecting fails, because of the bzero() before function "mysql_real_connect()"

          It locates on line 2025 in file libmariadb.c from rev.192

          If I have understood the code correctly, the "bzero" function which resets the options of mysql object is unnecessary here. Because if the reconnecting fails and enters into the if block below, the original option from mysql object would get lost ( yes it is not freed, but the option field in mysql object is 0 ).

          ---------------------------------------------------------------------------------------------------------
          // Is it a bug?
          bzero((char*) &mysql->options,sizeof(mysql->options));
          if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd,
          mysql->db, mysql->port, mysql->unix_socket,
          mysql->client_flag | CLIENT_REMEMBER_OPTIONS))

          { /* don't free options (CONC-118) */ memset(&tmp_mysql.options, 0, sizeof(struct st_mysql_options)); my_set_error(mysql, tmp_mysql.net.last_errno, tmp_mysql.net.sqlstate, tmp_mysql.net.last_error); mysql_close(&tmp_mysql); DBUG_RETURN(1); }
          tianhongxu Tianhong added a comment - Hey Georg, thanks for the support. I read the new code and thought that the first issue is still there: "Original options from client would get lost if reconnecting fails, because of the bzero() before function "mysql_real_connect()" It locates on line 2025 in file libmariadb.c from rev.192 If I have understood the code correctly, the "bzero" function which resets the options of mysql object is unnecessary here. Because if the reconnecting fails and enters into the if block below, the original option from mysql object would get lost ( yes it is not freed, but the option field in mysql object is 0 ). --------------------------------------------------------------------------------------------------------- // Is it a bug? bzero((char*) &mysql->options,sizeof(mysql->options)); if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd, mysql->db, mysql->port, mysql->unix_socket, mysql->client_flag | CLIENT_REMEMBER_OPTIONS)) { /* don't free options (CONC-118) */ memset(&tmp_mysql.options, 0, sizeof(struct st_mysql_options)); my_set_error(mysql, tmp_mysql.net.last_errno, tmp_mysql.net.sqlstate, tmp_mysql.net.last_error); mysql_close(&tmp_mysql); DBUG_RETURN(1); }
          georg Georg Richter added a comment -

          Hi Tanhong,

          it's correct bzeroing options should be removed.
          I uncommitted and pushed correct ed fix.

          Thanks for your help!

          georg Georg Richter added a comment - Hi Tanhong, it's correct bzeroing options should be removed. I uncommitted and pushed correct ed fix. Thanks for your help!
          tianhongxu Tianhong added a comment -

          My pleasure!

          tianhongxu Tianhong added a comment - My pleasure!

          People

            georg Georg Richter
            tianhongxu Tianhong
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.