This is the mail archive of the
gsl-discuss@sourceware.org
mailing list for the GSL project.
Re: free
- From: Jochen Küpper <jochen at fhi-berlin dot mpg dot de>
- To: GSL <help-gsl at gnu dot org>, GSL Discussion <gsl-discuss at sources dot redhat dot com>
- Date: Sun, 11 Jun 2006 20:59:09 +0200
- Subject: Re: free
- Followup-to: GSL,Discussion,<gsl-discuss@sources.redhat.com>
- Openpgp: id=CC1B0B4D; url=http://jochen-kuepper.de/computer/keys.asc
- References: <4958.165.91.115.246.1149968330.squirrel@neoweb.tamu.edu><448BC36B.9020405@btinternet.com><9e3becawi2.fsf@doze.jochen-kuepper.de><448C3875.6030506@btinternet.com><9e7j3nactq.fsf_-_@doze.jochen-kuepper.de><448C5EDC.7050301@btinternet.com>
- Reply-to: GSL Discussion <gsl-discuss at sources dot redhat dot com>
X-posted and Followup-To: GSL discuss
John D Lamb <J.D.Lamb@btinternet.com> writes:
> Jochen Küpper wrote:
>>> gsl_matrix_alloc and gsl_matrix free behave like alloc and free and
>>> so I guess gsl_matrix_alloc returns 0 on failure and gsl_matrix_free
>>> should not be called with a null pointer.
[...]
>> Actually it should be ok to call free with NULL, just not with any
>> other invalid pointer:
>>
>> ,----[man free]
>> | free() frees the memory space pointed to by ptr, which must have been
>> | returned by a previous call to malloc(), calloc() or realloc(). Otherwise,
>> | or if free(ptr) has already been called before, undefined behaviour occurs.
>> | If ptr is NULL, no operation is performed.
>> `----
[...]
> I checked the source code for gsl_matrix_free and it will fail if passed
> a null pointer.
Shouldn't the GSL free-routines be changed like the following patch?
,----
| @@ -74,6 +74,8 @@
| void
| FUNCTION (gsl_block, free) (TYPE (gsl_block) * b)
| {
| - free (b->data);
| - free (b);
| + if(b != 0) {
| + free (b->data);
| + free (b);
| + }
| }
`----
Greetings,
Jochen
--
Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de
Liberté, Égalité, Fraternité GnuPG key: CC1B0B4D
(Part 3 you find in my messages before fall 2003.)