Boost logo

Boost Users :

From: Abhishek Soni (sujanian.abhi_at_[hidden])
Date: 2008-05-06 01:58:20


Hi all

For past three days am trying to figure out the cause of error. I am using
shared_array, allocating it memory equal to size of data am populating it
with and then storing the data in the "shared_array". but when shared_ptr
goes out of scope and is internally deallocated, error is thrown....

I am populating my shared_array type data with data fetched from
database....

here's part of my code

*******************************************************************************************************************************************************************************

// ***********Main function***************

#include <stdio.h>
#include <occi.h>
#include <iostream>
#include <pthread.h>
#include "RtShDataDao.hpp" //My own class with function
declarations including rtGetRepositoryData(RtRepositoryDataVo &
r_repositoryData,const RtU32T id,const RtU32T aliasOrPublic, const RtC8T *
p_serviceIndication)
                    //RtU32T is unsigned int of size 32 bytes, RtC8t is
Signed Char
#include <string>

#include <exception>

using namespace std;
using namespace oracle::occi;

int main()
{

void get_RepositoryData();
get_RepositoryData();
}

void get_RepositoryData()
{
    RtShDataDao shDataDaoObj;
    RtU32T id = 8;
    RtU32T aliasOrPublic = 1;
    RtRepositoryDataVo repositoryData;// = new RtRepositoryDataVo(); //
RtRepositoryDataVo is class containing variables m_seq and mp_data
    repositoryData.m_seq = 0;
    RtC8T serviceIndication[50] = "service indication 8";
    printf("\nAddress in shared ptr is %p\n",repositoryData.mp_data.get());

    try
    {

shDataDaoObj.rtGetRepositoryData(repositoryData,id,aliasOrPublic,serviceIndication);
    }
    catch (RtExceptionUD &eud)
    {
        cout<<"Error---------------------"<<eud.errString<<endl;
    }
    catch (SQLException &se)
    {
        cout << " SQL Exception -----------------"<<se.what() <<endl;
    }
    catch (exception & e)
    {
        cout << " Exception ----------"<<e.what() ;
    }
    cout<<" Returned from RtGetRepositoryData "<<endl;
    cout<<endl<<" sequence "<<repositoryData.m_seq <<endl;
    cout<<"repositoryData.mp_data
"<<(repositoryData.mp_data.get())<<endl;
}

//*************** RtShDataDao.cpp***********************
// this class contains definitions of functions
//RtSpChar is defined as typedef shared_array<RtU8T> RtSpChar; in
RtShared_ptr.hpp

#include <occi.h>
#include "RtExceptionUD.hpp"
#include <iostream>

using namespace std;
using namespace oracle::occi;

extern StatelessConnectionPool *g_scp;

#include "RtShDataDao.hpp"

void RtShDataDao::rtGetRepositoryData(RtRepositoryDataVo &
r_repositoryData,const RtU32T id,const RtU32T aliasOrPublic, const RtC8T *
p_serviceIndication) throw (RtExceptionUD &, exception &,SQLException &)
{
    if(p_serviceIndication == NULL)
    {
        throw RtExceptionUD(" p_serviceIndication initialized with NULL");
    }
    if( aliasOrPublic < 0 )
    {
        throw RtExceptionUD(" aliasOrPublic initialized with unexpected
value ");
    }
    if( id <= 0 )
    {
        throw RtExceptionUD(" id initialized with unexpected value ");
    }
    Connection *l_conn = g_scp->getConnection();
    Statement *l_stmt = l_conn->createStatement();
    ResultSet * l_rs;
    int l_countRow = 0;
    ub2 rc = 0, rc1 = 0;
    sb2 ind = 0, ind1 = 0;

    switch (aliasOrPublic)
    {
    case 0:
        {
            Clob l_repData;
            l_stmt->setSQL(GET_REPOSITORY_DATA_PUBLIC);

            ub2 l_lenInt = sizeof(int);
            l_stmt->setDataBuffer(1,(void *)&id,OCCIINT,l_lenInt,&l_lenInt);

            ub2 l_lenString = strlen (p_serviceIndication)+1;
            l_stmt->setDataBuffer(2,(dvoid
*)p_serviceIndication,OCCI_SQLT_STR, l_lenString, &l_lenString);

            l_rs = l_stmt->executeQuery();

            l_rs->setDataBuffer(1,(void
*)&r_repositoryData.m_seq,OCCIINT,l_lenInt,&l_lenInt, &ind, &rc);

            ub2 l_lenClob;
            l_repData.setEmpty(l_conn);
            l_rs->setDataBuffer(2,&l_repData,OCCI_SQLT_CLOB, l_lenClob,
&l_lenClob, &ind1, &rc1);
            while (l_rs->next())
            {
                    if(!ind1)
                    {
                        unsigned int l_offset = 1;
                        r_repositoryData.mp_data = RtSpChar (new
RtU8T(l_repData.length()+1));

                        l_repData.read(l_repData.length(),(unsigned
char*)(r_repositoryData.mp_data.get()),l_repData.length(),l_offset);
                        r_repositoryData.mp_data[l_repData.length()] = '\0';
                        printf("address of the mp_data %p
/n",r_repositoryData.mp_data.get());
                        getchar();
                    }
                ++l_countRow;
            }
        break;
        }
    case 1:
        {
            Clob l_repData;
            l_stmt->setSQL(GET_REPOSITORY_DATA_ALIAS);

            ub2 l_lenInt = sizeof(int);
            l_stmt->setDataBuffer(1,(void *)&id,OCCIINT,l_lenInt,&l_lenInt);

            ub2 l_lenString = strlen (p_serviceIndication)+1;
            l_stmt->setDataBuffer(2,(dvoid
*)p_serviceIndication,OCCI_SQLT_STR, l_lenString, &l_lenString);

            l_rs = l_stmt->executeQuery();
            l_rs->setDataBuffer(1,(void
*)&r_repositoryData.m_seq,OCCIINT,l_lenInt,&l_lenInt, &ind, &rc);

            ub2 l_lenClob;
            l_repData.setEmpty(l_conn);
            l_rs->setDataBuffer(2,&l_repData,OCCI_SQLT_CLOB, l_lenClob,
&l_lenClob, &ind1, &rc1);
            while (l_rs->next())
            {
                    if(!ind1)
                    {
                        unsigned int l_offset = 1;
                        r_repositoryData.mp_data = RtSpChar (new
RtU8T(l_repData.length()+1));

                        l_repData.read(l_repData.length(),(unsigned
char*)(r_repositoryData.mp_data.get()),l_repData.length(),l_offset);
                        r_repositoryData.mp_data[l_repData.length()] = '\0';
                        printf("address of the mp_data %p
/n",r_repositoryData.mp_data.get());
                        getchar();
                    }

// unsigned int l_offset = 1;
// r_repositoryData.mp_data = RtSpChar(new
RtU8T(l_repData.length()));
// l_repData.read(l_repData.length(),(unsigned char
*)r_repositoryData.mp_data.get(),l_repData.length(),l_offset);
                ++l_countRow;
            }
            break;
        }
    }

    l_stmt->closeResultSet(l_rs);
    l_conn->terminateStatement(l_stmt);
    g_scp->releaseConnection(l_conn);

    if(l_countRow == 0)
        throw RtExceptionUD("RtShDataDao::getRepositoryData::No data fetched
....");
}

// This class contains definitions for variable m_seq and mp_data

#ifndef _RTREPOSITORYDATAVO_H
#define _RTREPOSITORYDATAVO_H

#include "RtDataType.h"
#include "RtShared_ptr.hpp"

using namespace boost;

// This class is a value object that shall have the repository data
corresponding to the public identity id or alias grp id.
class RtRepositoryDataVo {
public:
    // It is identity used for a set of service related transparent data.
    RtC8T mp_serviceInd[30];
    // The seqn is the sequence number which is used in order to maintain a
uniformity in data shared AS and HSS.
    RtU32T m_seq;
    // The data is the transparent data.
    RtSpChar mp_data;
    //shared_ptr<RtU8T> mp_data;
// ~RtRepositoryDataVo(){cout<<"Destruc Use count is
"<<mp_data.use_count()<<endl;}
};

#endif //_RTREPOSITORYDATAVO_H

//this class contains definitions for RtC8t and RtU32T

#ifndef _RTDATATYPE_H
#define _RTDATATYPE_H

    // unsigned char
    typedef unsigned char RtU8T;
    // unsigned short
    typedef unsigned short RtC16T;
    // unsigned int
    typedef unsigned int RtU32T;
    // unsigned long
    typedef unsigned long RtU64T;
    // signed char
    typedef signed char RtS8T;
    // signed short
    typedef signed short RtS16T;
    // signed int
    typedef signed int RtS32T;
    // signed long
    typedef signed long RtS64T;
    // char
    typedef char RtC8T;

#endif //_DATATYPE_H

*******************************************************************************************************************************************************************************

and here's the error am getting

Address in shared ptr is (nil)
address of the mp_data 0x82fa708 /n Returned from RtGetRepositoryData

 sequence 0
repositoryData.mp_data data clob to be populated with information
*** glibc detected *** ./a.out: free(): invalid next size (fast): 0x082fa708
***
======= Backtrace: =========
/lib/libc.so.6[0x431a2f7d]
/lib/libc.so.6(cfree+0x90)[0x431a65d0]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x43dacef1]
/usr/lib/libstdc++.so.6(_ZdaPv+0x1d)[0x43dacf4d]
./a.out[0x8061193]
./a.out[0x80611a7]
./a.out[0x8061296]
./a.out[0x805774c]
./a.out[0x8057776]
./a.out[0x8057806]
./a.out[0x805781c]
./a.out[0x8054ad2]
./a.out[0x8057556]
/lib/libc.so.6(__libc_start_main+0xdc)[0x43152dec]
./a.out(__gxx_personality_v0+0x3bd)[0x804ce91]
======= Memory map: ========
00110000-00294000 r-xp 00000000 fd:00 13844169
/app/oracle/product/11.1.0/db/lib/libnnz11.so
00294000-002b9000 rwxp 00184000 fd:00 13844169
/app/oracle/product/11.1.0/db/lib/libnnz11.so
002b9000-002ba000 rwxp 002b9000 00:00 0
002ba000-002bb000 r-xp 00000000 fd:00 14018711 /usr/lib/libaio.so.1.0.1
002bb000-002bc000 rwxp 00000000 fd:00 14018711 /usr/lib/libaio.so.1.0.1
002bc000-002ed000 r-xp 00000000 fd:00 13835865
/app/oracle/product/11.1.0/db/lib/libskgxp11.so
002ed000-002ef000 rwxp 00031000 fd:00 13835865
/app/oracle/product/11.1.0/db/lib/libskgxp11.so
002ef000-002f0000 --xp 002ef000 00:00 0
002f0000-002ff000 rwxp 002f0000 00:00 0
0037b000-00384000 r-xp 00000000 fd:00 7071017 /lib/libnss_files-2.5.so
00384000-00385000 r-xp 00008000 fd:00 7071017 /lib/libnss_files-2.5.so
00385000-00386000 rwxp 00009000 fd:00 7071017 /lib/libnss_files-2.5.so
0048e000-00493000 r-xp 00000000 fd:00 13844145
/app/oracle/product/11.1.0/db/lib/libnque11.so
00493000-00494000 rwxp 00005000 fd:00 13844145
/app/oracle/product/11.1.0/db/lib/libnque11.so
00612000-00a77000 r-xp 00000000 fd:00 13819009
/app/oracle/product/11.1.0/db/lib/liborasdkbase.so.11.1
00a77000-00a94000 rwxp 00464000 fd:00 13819009
/app/oracle/product/11.1.0/db/lib/liborasdkbase.so.11.1
00a94000-00a97000 rwxp 00a94000 00:00 0
00b71000-00b72000 r-xp 00b71000 00:00 0 [vdso]
00b72000-02486000 r-xp 00000000 fd:00 13844118
/app/oracle/product/11.1.0/db/lib/libclntsh.so.11.1
02486000-02527000 rwxp 01913000 fd:00 13844118
/app/oracle/product/11.1.0/db/lib/libclntsh.so.11.1
02527000-0253f000 rwxp 02527000 00:00 0
0253f000-03aef000 r-xp 00000000 fd:00 13819013
/app/oracle/product/11.1.0/db/lib/liborasdk.so.11.1
03aef000-03b7d000 rwxp 015b0000 fd:00 13819013
/app/oracle/product/11.1.0/db/lib/liborasdk.so.11.1
03b7d000-03b92000 rwxp 03b7d000 00:00 0
08048000-08114000 r-xp 00000000 fd:00 1276920
/home/abhisheks/projects/HSS/Implementation/app/a.out
08114000-08117000 rwxp 000cc000 fd:00 1276920
/home/abhisheks/projects/HSS/Implementation/app/a.out
082fa000-083a0000 rwxp 082fa000 00:00 0
4276e000-42787000 r-xp 00000000 fd:00 7072496 /lib/ld-2.5.so
42787000-42788000 r-xp 00018000 fd:00 7072496 /lib/ld-2.5.so
42788000-42789000 rwxp 00019000 fd:00 7072496 /lib/ld-2.5.so
427f2000-42804000 r-xp 00000000 fd:00 7072509 /lib/libnsl-2.5.so
42804000-42805000 r-xp 00012000 fd:00 7072509 /lib/libnsl-2.5.so
42805000-42806000 rwxp 00013000 fd:00 7072509 /lib/libnsl-2.5.so
42806000-42808000 rwxp 42806000 00:00 0
4313d000-43274000 r-xp 00000000 fd:00 7072497 /lib/libc-2.5.so
43274000-43276000 r-xp 00137000 fd:00 7072497 /lib/libc-2.5.so
43276000-43277000 rwxp 00139000 fd:00 7072497 /lib/libc-2.5.so
43277000-4327a000 rwxp 43277000 00:00 0
4327c000-432a1000 r-xp 00000000 fd:00 7072499 /lib/libm-2.5.so
432a1000-432a2000 r-xp 00024000 fd:00 7072499 /lib/libm-2.5.so
432a2000-432a3000 rwxp 00025000 fd:00 7072499 /lib/libm-2.5.so
432a5000-432a7000 r-xp 00000000 fd:00 7072498 /lib/libdl-2.5.so
432a7000-432a8000 r-xp 00001000 fd:00 7072498 /lib/libdl-2.5.so
432a8000-432a9000 rwxp 00002000 fd:00 7072498 /lib/libdl-2.5.so
432ab000-432be000 r-xp 00000000 fd:00 7072500 /lib/libpthread-2.5.so
432be000-432bf000 r-xp 00012000 fd:00 7072500 /lib/libpthread-2.5.so
432bf000-432c0000 rwxp 00013000 fd:00 7072500 /lib/libpthread-2.5.so
432c0000-432c2000 rwxp 432c0000 00:00 0
43ceb000-43cf6000 r-xp 00000000 fd:00 7072519
/lib/libgcc_s-4.1.1-20070105.so.1
43cf6000-43cf7000 rwxp 0000a000 fd:00 7072519
/lib/libgcc_s-4.1.1-20070105.so.1
43cf9000-43dd9000 r-xp 00000000 fd:00 14021099 /usr/lib/libstdc++.so.6.0.8
43dd9000-43ddc000 r-xp 000e0000 fd:00 14021099 /usr/lib/libstdc++.so.6.0.8
43ddc000-43dde000 rwxp 000e3000 fd:00 14021099 /usr/lib/libstdc++.so.6.0.8
43dde000-43de4000 rwxp 43dde000 00:00 0
b7d00000-b7d21000 rwxp b7d00000 00:00 0
b7d21000-b7e00000 --xp b7d21000 00:00 0
b7e16000-b7e69000 rwxp b7e16000 00:00 0
b7e69000-b7ecd000 r-xp 00000000 fd:00 13823471
/app/oracle/product/11.1.0/db/oracore/zoneinfo/timezlrg.dat
b7ecd000-b7ef4000 rwxp b7ecd000 00:00 0
b7efe000-b7f02000 rwxp b7efe000 00:00 0
bfe9c000-bfeb0000 rwxp bfe9c000 00:00 0 [stack]
bfeb0000-bfeb1000 rw-p bfeb0000 00:00 0
Aborted (core dumped)

there's another problem that am facing with the code.... its like that if i
change the size of the data then for some data size it does not give any
error, the programm executes smoothely..... Am running the code on limited
user on a linux machine, but if I run the same code for a root user there's
never an error.....

Kindly help me.. am stuck in it for past three days.... any help will be
appreciated



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net