Menu

#27 memory leak

open
nobody
None
5
2018-03-07
2006-03-06
Anonymous
No

mysql has a known memory leak between the call of
mysql_init, mysql_real_connect and mysql_close. I first
came across the bug for a different program and
searched mysql's bug list, it's been around since
version 3.23.x and affects upwards of 5.x. In any case,
there isn't much that you can do. However, in the
documentation you should explain that this exists and
that long runnnig programs like saslauthd if used with
pam will consume your swap until the machine stops
working. There are work arounds such as having
saslauthd cache its credentials or fork a process for
each request. Though not directly your problem, it
should be in big bold letters so that people know about
the potential OOM condition pam_mysql can bring.

Discussion

  • jean-seb

    jean-seb - 2006-03-09

    Logged In: YES
    user_id=1101802

    I confirm this memory leak:
    The only way I find to avoid this is to "dont fork" saslauthd

    In Centos/RHAS4, edit the file:
    /etc/sysconfig/saslauthd
    and add this:
    FLAGS="-n 0"

    The process "saslauthd" grow and grow ..and consume all your
    memory .. it's realy a Mysql bug?

     
  • Roland Hebertinger

    Logged In: YES
    user_id=37848

    same problem here. saslauthd ate all the memory and one of
    my servers stoped working. i searched through the
    mailinglists of cyrus-sasl and they said the problem is due
    to a pam module having a memory leak. i can confirm this
    with versions 0.6.2. and 0.7RC3 of pam_mysql. I'm still
    investigating this issue and will try to go back to an even
    older version of pam_mysql. I had no problems on older
    machines with 0.5, so i'll try this one next.

     
  • Roland Hebertinger

    Logged In: YES
    user_id=37848

    uups, it must read 0.7RC1, not RC3 :)

     
  • Nobody/Anonymous

    Logged In: NO

    Memory leak found in 0.6.2, so I assume it's the same on the 0.7RC1 series. Tested fix is this minor patch to 'pam_mysql-0.6.2/pam_mysql.c':

    __attribute__((destructor))
    void end_sql() {
    mysql_library_end();
    return;
    }

     
  • Dmitry Mikhailov

    My solution is the following patch against 'latest' pam_mysql-0.7RC1.
    But mysql_library_end() requires MySQL at least version 4.1.10
    For previous versions use mysql_server_end() instead.

    Someone may modify config script to figure out mysql library version and use the correct procedure.
    By the way, is the project maintained?

    --- pam_mysql.c.orig 2009-05-20 17:28:22.000000000 +0600
    +++ pam_mysql.c 2009-05-20 17:34:25.000000000 +0600
    @@ -2339,6 +2339,8 @@

    mysql_close(ctx->mysql_hdl);

    + mysql_library_end();
    +
    xfree(ctx->mysql_hdl);
    ctx->mysql_hdl = NULL;
    }

     
  • Johannes Pahl

    Johannes Pahl - 2018-03-07

    if you follow the instructions (like Dmitry Mikhailov did) https://dev.mysql.com/doc/refman/5.7/en/mysql-library-init.html
    Note:

    To avoid memory leaks after the application is done using the library (for example, after closing the connection to the server), be sure to call mysql_library_end() explicitly. This enables memory managment to be performed to clean up and free resources used by the library. See Section 27.8.7.40, “mysql_library_end()”.
    it works - tested for 1 year and it's ok since...
    Thank you

     

Log in to post a comment.