This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Realloc returns NULL
- From: "Carlos O'Donell" <carlos at systemhalted dot org>
- To: "Jeff Baumes" <jeff dot baumes at kitware dot com>
- Cc: libc-help at sourceware dot org
- Date: Thu, 18 Dec 2008 17:18:50 -0500
- Subject: Re: Realloc returns NULL
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=9GOuPPt6OlTBmTVWLOfdywtVNvpyMU+F9o1fvQkc00o=; b=cEioKseStrme+KtuQ5joHJchWtWoQOk+9ILyL6DbwvdtxsxjoRMHSW4E5pr0iDbWP5 0wq9y4c0n1hmFPY4xdeTDfeGxgeGohGzYBtqzRCasiBf+wXnzRE9ekPnXKpgC1hAdPhD XIFuhjApLFz5taQvIy2WpSYsM/hEM0TgECY1c=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=RSYCeFqV2wJ+lwf8NtvEMNfYh7JUZPV5pCEX+uGDAd6Udlwx7foLu22sz5sRV5ce0f 8DEY5uhJn3pz6RuK8fMYqe4Eq/0XTy+6zJHujn9wceIvaaV6XTVJom+tSiX5MtGG/231 caRuiFTLOiG3iNlaLNSuUxUbM140KnkWvnWrk=
- References: <2137e33e0812181411u7ce0e296rdf71d5af87fa191@mail.gmail.com>
On Thu, Dec 18, 2008 at 5:11 PM, Jeff Baumes <jeff.baumes@kitware.com> wrote:
> Is there any reason that realloc() could return NULL without running
> out of memory on the system? My system memory is at 0.5GB out of 4GB
> when it crashes, so it doesn't appear to be an out-of-memory error.
> The requested realloc call is for 320K on a pointer that currently is
> allocated for 160K. I am running a multi-threaded application, where
> the failure occurs in a "worker" thread (not the main thread).
> Valgrind does not come up with any memory errors. If I replace the
> realloc with a malloc, memcpy, and free, the error does not appear. I
> am using libc version 2.7 on Ubuntu, gcc version 4.2.4.
Did you check the value of errno? It will be set to ENOMEM if you ran
out of memory.
"realloc"
http://www.opengroup.org/onlinepubs/009695399/functions/realloc.html
- returns null if the size is zero (defined behaviour).
- returns null if it is out of memory (defined behaviour).
- could return null if ptr was not the result of a previous malloc,
calloc, or realloc (undefined behaviour).
- could return null if ptr was already freed (undefined behaviour).
Cheers,
Carlos.