Bug #64446 while( res-->next() ) Count being destroyed after first iterration.
Submitted: 24 Feb 2012 15:44 Modified: 30 Oct 2014 11:38
Reporter: Joseph Cameron Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / C++ Severity:S1 (Critical)
Version:1.1.0 OS:Linux (Linux (Debian 6))
Assigned to: CPU Architecture:Any
Tags: connector c++, Debian, next(), vmbox

[24 Feb 2012 15:44] Joseph Cameron
Description:
Win Vista running -

Oracle Vitual Box - Ver: 4.1.8r75457

Guest -
Debian release 6.0.4
Kernal Linux 2.6.32-5-686
Mem 2.0gb
Proc AMD Athlon II X2 245 proc.

NetBeans 7.1

From
http://dev.mysql.com/downloads/connector/cpp/#downloads
mysql-connector-c++-1.1.0-linux-glibc2.3-x86-32bit.tar.gz
---------------------------------
Is this related to following bug link because of running VMbox?
Boost not affecting this.
Related to Bug Report: http://bugs.mysql.com/bug.php?id=64380
----------------------------------

/* 
 * File:   main.cpp
 * Author: gdmps
 *
 * Created on February 13, 2012, 6:23 AM
 */

#include <cstdlib>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>

/* MySQL Connector/C++ specific headers */
#include <cppconn/driver.h>
#include <cppconn/connection.h>
#include <cppconn/statement.h>
#include <cppconn/resultset.h>
#include <cppconn/exception.h>
#include <cppconn/warning.h>

using namespace std;
using namespace sql;

string db_host = "localhost";
string db_user = "root";
string db_pass = "";

/*
 * 
 */

int main(int argc, char** argv) {
    
    bool new_db = true;
    bool verbose = true;
    bool update;
    int index;
    string start_date;

    Driver *driver;
	Connection *con;
	Statement *stmt;
	ResultSet *res;
    
    try
    {
        driver = get_driver_instance();
        con = driver -> connect( db_host, db_user, db_pass );
	} catch (SQLException &e) {
		cout << "ERROR: SQLException in " << __FILE__;
		cout << " (" << __func__<< ") on line " << __LINE__ << endl;
		cout << "ERROR: " << e.what();
		cout << " (MySQL error code: " << e.getErrorCode();
		cout << ", SQLState: " << e.getSQLState() << ")" << endl;

		return EXIT_FAILURE;
    }

    stmt = con->createStatement();
    
    stmt->execute( "USE SymbolData" );
    
    // NASDAQnasdaq table layout
    // "CREATE TABLE " + nasdaq_csv[index] + " (
    //      symbol varchar(10),
    //      name varchar(200),
    //      class varchar(20),
    //      type varchar(20),
    //      market_cap varchar(50),
    //      adr_tso varchar(20),
    //      ipo_year varchar(10),
    //      sector varchar(100),
    //      industry varchar(100),
    //      exchange varchar(20) )" );

    // Update NASDAQ Preferred Class
    if( verbose ) printf( "Updating Preferred NASDAQ database\n\n" );

    res = stmt->executeQuery("SELECT * FROM NASDAQnasdaq");

    if( verbose ) printf( "executeQuery returned  %d rows of data\n", res->rowsCount() );

    while( res->next() ) {
    
        cout << "Entered res->next " << endl;
    
        std::string s_symbol = res->getString("symbol");
        cout << "s_symbol " << s_symbol << endl;
    }
    delete stmt;
    delete res;
    delete con;
    return 0;
}
========================
It will execute thru next() once and out correctly,
then 'res' seems to get destroyed somehow.

Updating Preferred NASDAQ database

executeQuery returned  2772 rows of data
Entered res->next 
s_symbol FLWS
*** glibc detected *** /home/gdmps/NetBeansProjects/testboost/dist/Debug/GNU-Linux-x86/testboost: free(): invalid size: 0x082cde70 ***
======= Backtrace: =========
/lib/libc.so.6(+0x6b19a)[0xb721119a]
/lib/libc.so.6(+0x6c9e8)[0xb72129e8]
/lib/libc.so.6(cfree+0x6d)[0xb7215b2d]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb73ea701]
/usr/lib/libstdc++.so.6(_ZNSs4_Rep10_M_destroyERKSaIcE+0x1d)[0xb73c66bd]
/usr/lib/libstdc++.so.6(_ZNSsD1Ev+0x4c)[0xb73c80bc]
/home/gdmps/NetBeansProjects/testboost/dist/Debug/GNU-Linux-x86/testboost[0x804913f]
/lib/libc.so.6(__libc_start_main+0xe6)[0xb71bcc96]
/home/gdmps/NetBeansProjects/testboost/dist/Debug/GNU-Linux-x86/testboost[0x8048c31]
======= Memory map: ========
08048000-0804a000 r-xp 00000000 08:01 270959     /home/gdmps/NetBeansProjects/testboost/dist/Debug/GNU-Linux-x86/testboost
0804a000-0804b000 rw-p 00001000 08:01 270959     /home/gdmps/NetBeansProjects/testboost/dist/Debug/GNU-Linux-x86/testboost
082bc000-0834d000 rw-p 00000000 00:00 0          [heap]
b6400000-b6421000 rw-p 00000000 00:00 0 
b6421000-b6500000 ---p 00000000 00:00 0 
b6578000-b6582000 r-xp 00000000 08:01 423220     /lib/libnss_files-2.11.3.so
b6582000-b6583000 r--p 00009000 08:01 423220     /lib/libnss_files-2.11.3.so
b6583000-b6584000 rw-p 0000a000 08:01 423220     /lib/libnss_files-2.11.3.so
b6584000-b6585000 ---p 00000000 00:00 0 
b6585000-b6d87000 rw-p 00000000 00:00 0 
b6d87000-b6d8a000 r-xp 00000000 08:01 283036     /usr/lib/libgpg-error.so.0.4.0
b6d8a000-b6d8b000 rw-p 00002000 08:01 283036     /usr/lib/libgpg-error.so.0.4.0
b6d8b000-b6d9a000 r-xp 00000000 08:01 285499     /usr/lib/libtasn1.so.3.1.9
b6d9a000-b6d9b000 rw-p 0000e000 08:01 285499     /usr/lib/libtasn1.so.3.1.9
b6d9b000-b6d9d000 r-xp 00000000 08:01 362382     /lib/libkeyutils.so.1.3
b6d9d000-b6d9e000 rw-p 00001000 08:01 362382     /lib/libkeyutils.so.1.3
b6d9e000-b6da0000 r-xp 00000000 08:01 423214     /lib/libdl-2.11.3.so
b6da0000-b6da1000 r--p 00001000 08:01 423214     /lib/libdl-2.11.3.so
b6da1000-b6da2000 rw-p 00002000 08:01 423214     /lib/libdl-2.11.3.so
b6da2000-b6da8000 r-xp 00000000 08:01 285611     /usr/lib/libkrb5support.so.0.1
b6da8000-b6da9000 rw-p 00005000 08:01 285611     /usr/lib/libkrb5support.so.0.1
b6da9000-b6daa000 rw-p 00000000 00:00 0 
b6daa000-b6dac000 r-xp 00000000 08:01 360521     /lib/libcom_err.so.2.1
b6dac000-b6dad000 rw-p 00001000 08:01 360521     /lib/libcom_err.so.2.1
b6dad000-b6dcf000 r-xp 00000000 08:01 285613     /usr/lib/libk5crypto.so.3.1
b6dcf000-b6dd0000 rw-p 00022000 08:01 285613     /usr/lib/libk5crypto.so.3.1
b6dd0000-b6e7c000 r-xp 00000000 08:01 285615     /usr/lib/libkrb5.so.3.3
b6e7c000-b6e82000 rw-p 000ac000 08:01 285615     /usr/lib/libkrb5.so.3.3
b6e82000-b6e98000 r-xp 00000000 08:01 285518     /usr/lib/libsasl2.so.2.0.23
b6e98000-b6e99000 rw-p 00015000 08:01 285518     /usr/lib/libsasl2.so.2.0.23
b6e99000-b6ea9000 r-xp 00000000 08:01 423219     /
lib/libresolv-2.11.3.so
b6ea9000-b6eaa000 r--p 00010000 08:01 423219     /lib/libresolv-2.11.3.so
b6eaa000-b6eab000 rw-p 00011000 08:01 423219     /lib/libresolv-2.11.3.so
b6eab000-b6eae000 rw-p 00000000 00:00 0 
b6eae000-b6f1f000 r-xp 00000000 08:01 283044     /usr/lib/libgcrypt.so.11.5.3
b6f1f000-b6f22000 rw-p 00070000 08:01 283044     /usr/lib/libgcrypt.so.11.5.3
b6f22000-b6fb6000 r-xp 00000000 08:01 285512     /usr/lib/libgnutls.so.26.14.12
b6fb6000-b6fba000 rw-p 00093000 08:01 285512     /usr/lib/libgnutls.so.26.14.12
b6fba000-b6fcd000 r-xp 00000000 08:01 279630     /usr/lib/libz.so.1.2.3.4
b6fcd000-b6fce000 rw-p 00013000 08:01 279630     /usr/lib/libz.so.1.2.3.4
b6fce000-b6ffc000 r-xp 00000000 08:01 285618     /usr/lib/libgssapi_krb5.so.2.2
b6ffc000-b6ffd000 rw-p 0002d000 08:01 285618     /usr/lib/libgssapi_krb5.so.2.2
b6ffd000-b7004000 r-xp 00000000 08:01 423232     /lib/librt-2.11.3.so
b7004000-b7005000 r--p 00006000 08:01 423232     /lib/librt-2.11.3.so
b7005000-b7006000 rw-p 00007000 0RUN FAILED (exit value 1, total time: 114ms)8:01 423232     /lib/librt-2.11.3.so

How to repeat:
//here is short table for 'SymbolData' database
-- phpMyAdmin SQL Dump
-- version 3.3.7deb7
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Feb 24, 2012 at 09:40 AM
-- Server version: 5.1.49
-- PHP Version: 5.3.3-7+squeeze8

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `SymbolData`
--

-- --------------------------------------------------------

--
-- Table structure for table `NASDAQnasdaq`
--

CREATE TABLE IF NOT EXISTS `NASDAQnasdaq` (
  `symbol` varchar(10) DEFAULT NULL,
  `name` varchar(200) DEFAULT NULL,
  `class` varchar(20) DEFAULT NULL,
  `type` varchar(20) DEFAULT NULL,
  `market_cap` varchar(50) DEFAULT NULL,
  `adr_tso` varchar(20) DEFAULT NULL,
  `ipo_year` varchar(10) DEFAULT NULL,
  `sector` varchar(100) DEFAULT NULL,
  `industry` varchar(100) DEFAULT NULL,
  `exchange` varchar(20) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `NASDAQnasdaq`
--

INSERT INTO `NASDAQnasdaq` (`symbol`, `name`, `class`, `type`, `market_cap`, `adr_tso`, `ipo_year`, `sector`, `industry`, `exchange`) VALUES
('FLWS', '1-800 FLOWERS.COM- Inc.', NULL, NULL, '79772040', 'n/a', '1999', 'Consumer Services', 'Other Specialty Stores', 'NASDAQ'),
('FCTY', '1st Century Bancshares- Inc', NULL, NULL, '37980600', 'n/a', 'n/a', 'Finance', 'Major Banks', 'NASDAQ'),
('FCCY', '1st Constitution Bancorp (NJ)', NULL, NULL, '42184560', 'n/a', 'n/a', 'Finance', 'Savings Institutions', 'NASDAQ'),
('SRCE', '1st Source Corporation', NULL, NULL, '624695400', 'n/a', 'n/a', 'Finance', 'Major Banks', 'NASDAQ'),
('FUBC', '1st United Bancorp- Inc. (FL)', NULL, NULL, '183348000', 'n/a', 'n/a', 'Finance', 'Major Banks', 'NASDAQ'),
('TCHC', '21st Century Holding Company', NULL, NULL, '26142340', 'n/a', '1998', 'Finance', 'Property-Casualty Insurers', 'NASDAQ'),
('VNET', '21Vianet Group- Inc.', NULL, NULL, '172971500', 'n/a', 'n/a', 'Technology', 'Computer Software: Programming- Data Processing', 'NASDAQ'),
('SSRX', '3SBio Inc.', NULL, NULL, '233516242.26', '19508458', '2007', 'Consumer Durables', 'Major Pharmaceuticals', 'NASDAQ'),
('JOBS', '51job- Inc.', NULL, NULL, '475151365.78', '10507549', '2004', 'Technology', 'Diversified Commercial Services', 'NASDAQ'),
('EGHT', '8x8 Inc', NULL, NULL, '299743200', 'n/a', 'n/a', 'Public Utilities', 'Telecommunications Equipment', 'NASDAQ');

Suggested fix:
No idea.
[24 Feb 2012 15:45] Joseph Cameron
update to Synopsis.
[26 Apr 2012 18:03] Sveta Smirnova
Thank you for the report.

Verified as described.
[23 Apr 2013 20:59] Lawrenty Novitsky
I could not repeat the bug, but I must admit I did not recreate your exact environment.

I have a question. Will anything change if take symbol variable declaration out of while (res->next()) block - i.e. if make it not local to that block?
[29 Apr 2013 20:02] Sveta Smirnova
Joseph,

please try with current version 1.1.3: I can not repeat the issue since version 1.1.1
[30 May 2013 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".