Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: double free Date: Tue, 05 Jul 2016 08:43:14 -0700 Organization: None to speak of Lines: 51 Message-ID: References: <577ba42f.13700328@news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="27274"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19MjPUhunqgL4WVFJQaCphs" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:xFJraj4WPMfZkmfCa/khVWdlJH8= sha1:1e4VUNDHt7CORT/j+6ldeuwL8KY= Xref: csiph.com comp.lang.c:90038 Richard Heathfield writes: > On 05/07/16 13:16, Richard Bos wrote: > > >> Ditch this book. It is misleading you, and the author is incompetent. > > Possible. Also possible: the author has been misquoted and/or > misinterpreted. (I have no evidence either way. I just know how very, > very possible it is.) The book in question is "Understanding and Using C Pointers" by Richard Reese, published by O'Reilly. I have a copy. http://shop.oreilly.com/product/0636920028000.do The quoted excerpts are accurate, with one small wording change. G G referred to a "runtime error". The actual wording in the book's discussion of a "double free" is: The term *double free* refers to an attempt to free a block of memory twice. A simple example follows: int *pi = (int*) malloc(sizeof(int)); *pi = 5; free(pi); ... free(pi); The execution of the second free function will result in a runtime exception. The phrase "runtime error", as Eric Sosman points out, could be consistent with undefined behavior, which might have no visible effects. The phrase "runtime exception", I think, clearly implies some visible result. (I don't assume it refers to C++ exceptions.) FWIW, when I run the above code on my own system, there is an explicit runtime error: *** Error in `./c': double free or corruption (fasttop): 0x0000000008829010 *** Aborted On another system (Solaris 9), there is no visible indication of an error. Both are of course consistent with the undefined behavior of this construct. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"