[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

kørt fast (pointere)



Hejsa

 Nu er jeg ved at være kørt rigtigt godt og grundigt fast i mit projekt! 

 Jeg har nogle pointer fis, og allokering af noget dynamiske memory til en
double linked liste (snuppet fra glib). Når jeg ryder op i denne liste, så
laver den en segmentation fault, og jeg kan simpelthen ikke gennemskue
hva' pokker det er der går galt... Håber nogen kan hjælpe..

 Her er min rutine :

----------------------- select_query --------------------
gchar *select_query(char *query)
{                       
GList *list = NULL,*node;
int id;                 
MYSQL_RES *res;         
MYSQL_ROW row; 
char r[50];
char t[5];
gpointer point;
        mysql_query(&mysql,query);
        res = mysql_store_result(&mysql);
        if (mysql_affected_rows(&mysql)==-1) exiterr(1);
//      if (res==NULL) exiterr(1);  
        while ((row=mysql_fetch_row(res))) {
                snprintf(r,36,"%s                           ",row[0]);
                snprintf(t,4,"%u",atoi(row[1]));
                strcat(r,t);  

// Allocate memory to a string...
                point = (char *) malloc(sizeof(r));
                strcpy(point,r);
                list = g_list_append(list,point);
                r[0]=0;
                }
        mysql_free_result(res);
        id = selection(list);
        if (id==-1) return "";
        node = g_list_nth(list,id);
        strcpy(query_return,node->data);
        while (list){   
                node = g_list_nth(list,g_list_length(list));
                free(node->data);                       <-- her fejler den
                list = g_list_remove(list,node->data);
                }       
        g_list_free(list);
        return query_return;
}                       
--------------------- end select_query ------------------

 g_list_xxxx funktionerne er næsten altid defineret således:

GList*      g_list_append   (GList *list, gpointer data);

glist er defineret som

struct GList
 {
   gpointer data;
   GList *next;
   GList *prev;
 };

Thomas Mørch
licensed ham, with callsign OZ2AFO. License category: CEPT-1

If God had intended man to smoke He would have set him on fire.



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *