Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6947869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:44:55+00:00 2026-05-27T13:44:55+00:00

Recently, I started to work on a C program that makes use of the

  • 0

Recently, I started to work on a C program that makes use of the libmysqlclient. When checking my code with valgrind, it reported memory leaks. The following minimal code snippet reproduces the behavior:

#include <mysql.h>

int main(void)
{
    MYSQL* mysql = mysql_init(0);

    mysql_close(mysql);

    return 0;
}

Checking the resulting program with valgrind tells me:

==25614== LEAK SUMMARY:
==25614==    definitely lost: 0 bytes in 0 blocks
==25614==    indirectly lost: 0 bytes in 0 blocks
==25614==      possibly lost: 0 bytes in 0 blocks
==25614==    still reachable: 288 bytes in 3 blocks
==25614==         suppressed: 0 bytes in 0 blocks

According to the MySQL API Reference, mysql_close()…

Closes a previously opened connection. mysql_close() also deallocates the connection handle pointed to by mysql if the handle was allocated automatically by mysql_init() or mysql_connect().

However, valgrind reports un-freed memory. What’s wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:44:55+00:00Added an answer on May 27, 2026 at 1:44 pm

    Digging through the docs, I found the function mysql_library_end() that solves the issue.

    Citing from the MySQL API Reference:

    This function finalizes the MySQL library. You should call it when you are done using the library (for example, after disconnecting from the server).

    On a personal note, I find it rather annoying that libmysqlclient forces its users to call its own cleanup function. IMO, a nicer solution would be to call mysql_library_end() automatically whenever the connection count drops to zero.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently, I started creating a program for the company I work for. Just as
I have recently started work on an application that is already deployed to production.
I have recently started work on a project that has already been running for
I have recently started work at a company that has a website. The previous
I've recently started work on a new project using PHP5 and want to use
I recently started work on a personal coding project using C++ and KDevelop. Although
I've recently started work on the Compact Framework and I was wondering if anyone
An application I have recently started work on has to register two dll's, because
I recently started using Eclipse at work for my Java servlet projects. I've been
My work place recently started a SOA initiative. After a year-long examination of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.