[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
 

Re: [CPROG] kørt fast (pointere)



"Thomas M." <sslug@sslug> skrev:

> Håber nogen kan hjælpe..

Jeg kan prøve; det er lidt tid siden, jeg har haft kigget på glib, så
det bliver med forbehold - som altid, i øvrigt :-).

>         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);

Først: din g_list_free(list) har ikke noget formål, da du aldrig
kommer til den inden "list" er 0 - men pyt med det.


g_list_nth() bruger vel indeksering fra nul; så når du tager
list[g_list_length(list)] når du 1 ud over sidste element, og der går
kludder i det (node->data bruger en 0-pointer).

Jeg ville lave løkken som:

	while (list) {
		free(list->data);
		list = g_list_remove_link(list, list);
	}

-- 
Regards, Anders                         If a Microsoft product
(address is valid)                      fails, who do you sue?


 
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] *