From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu From: "Douglas A. Gwyn" Message-ID: <3D87DF03.9736895E@null.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit References: , <20020917111727.U6063@cackle.proxima.alt.za> Subject: Re: [9fans] manual suggestions and upas/fs bug Date: Wed, 18 Sep 2002 08:37:18 +0000 Topicbox-Message-UUID: ee44b10c-eaca-11e9-9e20-41e7f4b1d025 Lucio De Re wrote: > char *p0 = realloc(p, n); > if (p0 == 0) > panic ("realloc failed"); > p = p0; > would be a lot saner. I forget the semantics, but realloc(p, n) need > not return p even if the reallocation succeeds. What I don't know is > what happens to the space pointed to by p, I assume it's released. Actually you don't have to be very careful if you're going to abort anyway. (Although the returned pointer needs to be checked, even for a shrink request.) But if you want to recover more intelligently, you don't want to lose the old pointer if the realloc fails; either the old data needs to be retained (so you need to use the old pointer) or else you want to free the old storage (otherwise you have a memory leak, which will exacerbate the tight-storage situation).