[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## [Help-gsl] Re: free

**From**: |
John D Lamb |

**Subject**: |
[Help-gsl] Re: free |

**Date**: |
Sun, 11 Jun 2006 19:20:12 +0100 |

**User-agent**: |
Thunderbird 1.5 (X11/20060317) |

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.*
>* `----*
>* *
Thanks. Somehow I'd never noticed, probably because I mostly use C++,
where delete 0 has no effect, and so seldom worry about malloc and free.
I checked the source code for gsl_matrix_free and it will fail if passed
a null pointer. In other words
gsl_matrix* p = 0;
free( p );
is correct (if pointless) code, but
gsl_matrix* p = 0;
gsl_matrix_free( p );
will always create a segmentation fault. Hence, in more complex code,
its still useful to write
if( p != 0 ){
gsl_matrix_free( p );
p = 0;
}
--
JDL

**[Help-gsl] Help with GSL Matrices**, *adarsh*, `2006/06/10`
*Message not available*
**Re: [Help-gsl] Help with GSL Matrices**, *John D Lamb*, `2006/06/11`
**Re: [Help-gsl] Help with GSL Matrices**, *Jochen Küpper*, `2006/06/11`
**Re: [Help-gsl] Help with GSL Matrices**, *John D Lamb*, `2006/06/11`
**free (was: [Help-gsl] Help with GSL Matrices)**, *Jochen Küpper*, `2006/06/11`
**[Help-gsl] Re: free**,
*John D Lamb* **<=**
**[Help-gsl] Re: free**, *Jochen Küpper*, `2006/06/11`
**[Help-gsl] Re: free**, *Brian Gough*, `2006/06/12`
**Re: [Help-gsl] Re: free**, *John D Lamb*, `2006/06/12`
**Re: [Help-gsl] Re: free**, *Jochen Küpper*, `2006/06/12`
**Re: [Help-gsl] Re: free**, *Brian Gough*, `2006/06/14`

**Re: [Help-gsl] Help with GSL Matrices**, *adarsh*, `2006/06/11`