MySQL Forums
Forum List  »  Connector/C++

free() invalid pointer in prepared statement
Posted by: 7 reeds
Date: October 13, 2015 04:18PM


This may end up in finger pointing but i have to start somewhere...

I am on RedHat 6.7; I have the most recent MySQL yum repo versions of everything

mysql-community-server.x86_64 5.6.27-2.el6 plus the client and libs
mysql-connector-c++.x86_64 1.1.6-1 plus most of the other conntors

I have a C++ project that consists of an executable; a ".so" plugin for PAM (Pluggable Auth Modules); and, a library that allows the first two things to actually operate. The library, amoung other things, inserts records into a remote MySQL database during user login "session" starts and stops.

This works for the commandline exectuable. This works for what I consider "normal" PAM operations like SSH and GDM. If you are unaware, PAM is an authentication layer that, by default, sits between system and user level applications and /etc/passwd or LDAP or AD or ...

So for most of my use cases this all works, no problem. I have a case where it dramatically fails though.

There is a Linux "remote desktop" service called "xrdp". Windows clients can RDP to Linux servers running xrdp and get linus desktop environments. My PAM module (the exact same code that works for SSH and console logins) blows up on the first prepared "stmt->execute();" or the close or the delete that comes after it. My diagnostic prints don't make it out in time to know which element is actually crashing.

The first part of the message I get is:

*** glibc detected *** /usr/sbin/xrdp-sesman: free(): invalid pointer: 0x00000000015be9b0 ***
======= Backtrace: =========

My code in this section looks like (edited for brevity):

/* Create a connection */
driver = get_driver_instance();
con = driver->connect("", "myUser", "passwird");

/* Connect to the MySQL test database */

MyPlugin_Lib::EventRecord item;
for (int i = 0; !eventList.empty(); eventList.pop_front(), i++) {
try {
item = eventList.front();

std::string dateTmp = MyUtilities::MyUtilities::UpperCase(item.getDate().c_str());

snprintf(insertSQL, 1024,
"INSERT INTO %s (event) VALUES(UPPER(?))",

sql::PreparedStatement *sth = con->prepareStatement(insertSQL);

int col = 1;

sth->setString(col++, item.getEvent().c_str());
#ifdef DEBUG_2
syslog(LOG_AUTHPRIV | LOG_DEBUG, "%s: event=%s",
__func__, item.getEvent().c_str());

#ifdef DEBUG_2
"%s: before execute", __func__);
#ifdef DEBUG_2
"%s: after execute", __func__);
#ifdef DEBUG_2
"%s: after close", __func__);

delete sth;
#ifdef DEBUG_2
"%s: after delete", __func__);
sth = NULL;
} catch (MyUtilities::MyException & e) {
"%s: userTracking DB insert failed: %s",
__func__, e.what());
syslog(LOG_AUTHPRIV | LOG_DEBUG, "%s", error);
throw MyUtilities::MyException(error);
} catch (...) {
"%s: unknown exception", __func__);

delete con;

the execute does not happen and the syslog statement just before it and all of them after do not reach the log

I am looking for ideas. Attaching to the/a process in this case to try to debug seems like a non-starter as PAM is not "running".

Options: ReplyQuote

Written By
free() invalid pointer in prepared statement
October 13, 2015 04:18PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.