Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| 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 <ike@iceland.freeshell.org> |
| 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 | <slrn3vfsmo7f16.kvv.ike@iceland.freeshell.org> (permalink) |
| References | <mm03eu$tnt$1@speranza.aioe.org> |
| 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 |
Show key headers only | View raw
On 2015-06-19, Morten W. Petersen <morphex@gmail.com> 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.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Linked lists, message passing "Morten W. Petersen" <morphex@gmail.com> - 2015-06-19 05:49 +0200
Re: Linked lists, message passing Ike Naar <ike@iceland.freeshell.org> - 2015-06-19 06:51 +0000
Re: Linked lists, message passing "Morten W. Petersen" <morphex@gmail.com> - 2015-06-19 09:08 +0200
Re: Linked lists, message passing Barry Schwarz <schwarzb@dqel.com> - 2015-06-19 02:08 -0700
Re: Linked lists, message passing "Morten W. Petersen" <morphex@gmail.com> - 2015-06-19 14:11 +0200
Re: Linked lists, message passing raltbos@xs4all.nl (Richard Bos) - 2015-06-19 13:47 +0000
Re: Linked lists, message passing "Morten W. Petersen" <morphex@gmail.com> - 2015-06-19 15:52 +0200
Re: Linked lists, message passing Robert Wessel <robertwessel2@yahoo.com> - 2015-06-19 22:07 -0500
Re: Linked lists, message passing raltbos@xs4all.nl (Richard Bos) - 2015-06-27 12:25 +0000
Re: Linked lists, message passing "Morten W. Petersen" <morphex@gmail.com> - 2015-06-29 09:03 +0200
Re: Linked lists, message passing raltbos@xs4all.nl (Richard Bos) - 2015-07-03 17:28 +0000
Re: Linked lists, message passing "Morten W. Petersen" <morphex@gmail.com> - 2015-07-03 22:16 +0200
Re: Linked lists, message passing Morris Dovey <mrdovey@iedu.com> - 2015-07-03 16:44 -0500
Re: Linked lists, message passing "Morten W. Petersen" <morphex@gmail.com> - 2015-07-04 01:12 +0200
Re: Linked lists, message passing Morris Dovey <mrdovey@iedu.com> - 2015-07-03 18:50 -0500
Re: Linked lists, message passing "Morten W. Petersen" <morphex@gmail.com> - 2015-07-04 09:39 +0200
Re: Linked lists, message passing Morris Dovey <mrdovey@iedu.com> - 2015-07-04 04:34 -0500
Re: Linked lists, message passing Bartc <bc@freeuk.com> - 2015-07-04 11:01 +0100
Re: Linked lists, message passing Geoff <geoff@invalid.invalid> - 2015-07-04 11:43 -0700
Re: Linked lists, message passing "Morten W. Petersen" <morphex@gmail.com> - 2015-07-05 18:49 +0200
Re: Linked lists, message passing Geoff <geoff@invalid.invalid> - 2015-07-05 12:30 -0700
Re: Linked lists, message passing "Morten W. Petersen" <morphex@gmail.com> - 2015-07-05 22:39 +0200
Re: Linked lists, message passing Geoff <geoff@invalid.invalid> - 2015-07-05 15:08 -0700
Re: Linked lists, message passing glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-07-06 01:05 +0000
Re: Linked lists, message passing Geoff <geoff@invalid.invalid> - 2015-07-05 23:55 -0700
Re: Linked lists, message passing "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-04 11:48 -0700
Re: Linked lists, message passing Morris Dovey <mrdovey@iedu.com> - 2015-07-03 18:51 -0500
Re: Linked lists, message passing G G <gdotone@gmail.com> - 2015-07-03 18:13 -0700
Re: Linked lists, message passing Richard Heathfield <rjh@cpax.org.uk> - 2015-06-19 08:12 +0100
Re: Linked lists, message passing "Morten W. Petersen" <morphex@gmail.com> - 2015-06-19 09:30 +0200
Re: Linked lists, message passing Richard Heathfield <rjh@cpax.org.uk> - 2015-06-19 08:59 +0100
Re: Linked lists, message passing Noob <root@127.0.0.1> - 2015-06-19 10:14 +0200
Re: Linked lists, message passing Richard Heathfield <rjh@cpax.org.uk> - 2015-06-19 09:40 +0100
Re: Linked lists, message passing Ian Collins <ian-news@hotmail.com> - 2015-06-20 15:14 +1200
Re: Linked lists, message passing jacobnavia <jacob@jacob.remcomp.fr> - 2015-06-19 18:10 +0200
Re: Linked lists, message passing Richard Heathfield <rjh@cpax.org.uk> - 2015-06-19 17:32 +0100
Re: Linked lists, message passing Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-06-29 00:56 -0700
Re: Linked lists, message passing Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-06-29 00:49 -0700
Re: Linked lists, message passing Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-11 08:32 -0700
csiph-web