Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ike Naar Newsgroups: comp.lang.c Subject: Re: Linked lists, message passing Date: Fri, 19 Jun 2015 06:51:15 +0000 (UTC) Organization: A noiseless patient Spider Lines: 33 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Date: Fri, 19 Jun 2015 06:51:15 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="0be15772a183805a7eecac7d41b73a46"; logging-data="26753"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19m9I/Zrkcv43MwKTBShC6f" User-Agent: slrn/0.9.9p1 (NetBSD) Cancel-Lock: sha1:Jtf8Go9AZModqVWFLhioiCHN4yY= Xref: csiph.com comp.lang.c:63570 On 2015-06-19, Morten W. Petersen wrote: > [...] > https://github.com/morphex/smash_xml/blob/c7a6017a75021432dbdb52178800e15dd4bc0061/message.c > [...] > Do you see any obvious problems with what in the code above? This part has a problem: struct message_linked_list *working_free = head; while (working_free) { printf("Free: %s\n", working_free->data); free(working_free); working_free = working_free->next; } The statement working_free = working_free->next; has undefined behaviour because the value of a pointer that refers to space deallocated by the free() function is used. One possible workaround would be struct message_linked_list *working_free = head; while (working_free) { printf("Free: %s\n", working_free->data); struct message_linked_list *next = working_free->next; free(working_free); working_free = next; } And I would probably move this code to a separate function.