Thread

  1. creating a pgconnection (or pgdatabase) object on the heap gives segmentation fault...

    ravindranathm <ravindranathm@integramicro.com> — 2001-03-22T14:57:28Z

    Hi...
    
    find the following details about the bug and please send a response/bugfix.
    
    ------------------------------
    Testing platform details...
        Postgress Version        :    7.0.3
        Platform                       :    Linux 6.2 on a Compaq Server
        System Memory           :    1 GB
        Disk Space                  :    6 GB
        library                          :    libpq++
    
    Bug description...
    1    - Try to create a PgConnection object or a PgDatabase object on the heap using new
                PgDatabase *conn = new PgDatabase ("user=xyz dbname=abc");
                or
                PgConnection *conn = new PgConnection ("user=xyz dbname=abc");
    
        Execute the program after compiling.  When the above is executed you get the following error:
                Segmentation fault (core dumped)
    
        Note:  If you create on the stack using         
                PgDatabase conn = PgDatabase ("user=xyz dbname=abc");
                or
                PgConnection conn = PgConnection ("user=xyz dbname=abc");
                then, it works.
    
    
    2.    - No default constructor available for connection object
                A call like
                    PgDatabase conn = PgConnection;
                will not compile and gives an error message saying...    
                    PgDatabase::PgDatabase() is protected.
    
            Therefore, If one wants to create an array of connections, (for ex: to implement a connection pool),
            a call like PgConnection conns[CONNECTIONS]; won;t work.
    
    
    To overcome the above 2 problems, we tried creating a class by inheriting from pgDatabase, which provides a 
    default constructor.
    ex:
        class mydb : public PgDatabase {
            public:
                mydb() : PgDatabase() { }
                mydb(string& constr) : PgDtabase (constr.c_str()) { }
        };
    
    Then the function calls:
        mydb* con1 = new mydb();
        mydb* con2 = new mydb("user=xyz dbname=abc");
    are working properly...
    but...
        then the calls to free the memory give segmentation fault.
            delete con1;
            delete con2;
    
    
    Please kindly, check the above and let me know that my analysis is correct or wrong.
    In previous version of postgres i.e. 6.x, this problem does not exist. Also find
    herewith attached some sample code, we used for testing...
    
    
    sincerely...
    
    Ravindranath M