Seg Fault: Debugging Beginner



Thanks all for helping me throughout the last two weeks. 
I have a code snippet that compiles prefectly but the app then gives a 
segmentation fault on running. Same code snippet elsewhere in the application 
works alright.
How can I correct it? What do seg fault generally mean?


The code is given below.

void display_db(void) {
        int i, j;
    gint row_status = -1;
    gchar *text[3];
    PGresult *res;
    PGconn *conn;
    conn = PQconnectdb(CONSTRING);
    if(PQstatus(conn) == CONNECTION_BAD){
        fprintf(stderr, "Connection to database failed.\n");
        fprintf(stderr, "%s", PQerrorMessage(conn));
        PQfinish(conn);
        exit(1);
        }

        gtk_clist_clear(GTK_CLIST(lookup_widget (GTK_WIDGET(window1), "clist1")));
    gtk_clist_freeze(GTK_CLIST(lookup_widget (GTK_WIDGET(window1), 
"clist1")));
        for(i = 0; i < PQntuples(res); i++) {
                for(j=0; j <PQnfields(res); j++) {
            text[j] = PQgetvalue(res, i, j);
            }
            row_status = gtk_clist_append(GTK_CLIST(lookup_widget 
(GTK_WIDGET(window1), "clist1")), text);
        }
        g_free(text);
    PQclear(res);    
    PQfinish(conn);
    gtk_clist_thaw(GTK_CLIST(lookup_widget (GTK_WIDGET(window1), "clist1")));
}


-- 
Sukrit K Mehra
Email: sukrit mehra amaltaas biz





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]