help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-gsl] [PATCH] BUG FIX: allow NULL pointers in gsl_matrix_free, gsl_


From: Leo Razoumov
Subject: [Help-gsl] [PATCH] BUG FIX: allow NULL pointers in gsl_matrix_free, gsl_rng_free, gsl_vector_free
Date: Thu, 8 Jan 2009 22:39:14 -0500 (EST)
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)

Long standing C-language idiom allows one to pass NULL pointer as an argument to various "free" functions (see "man free"). Unfortunately, GSL functions gsl_matrix_free, gsl_rng_free, gsl_vector_free (and possibly several more) do not follow this convention and will crash the program if called with NULL pointer. This simple patch fixes the problem.

--Leo--

---
 matrix/init_source.c |    1 +
 rng/rng.c            |    1 +
 vector/init_source.c |    1 +
 3 files changed, 3 insertions(+), 0 deletions(-)

----8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<----

diff --git a/matrix/init_source.c b/matrix/init_source.c
index c0fa819..f8302ff 100644
--- a/matrix/init_source.c
+++ b/matrix/init_source.c
@@ -182,6 +182,7 @@ FUNCTION (gsl_matrix, alloc_from_matrix) (TYPE(gsl_matrix) 
* mm,
 void
 FUNCTION (gsl_matrix, free) (TYPE (gsl_matrix) * m)
 {
+  if (!m){ return; }
   if (m->owner)
     {
       FUNCTION(gsl_block, free) (m->block);
diff --git a/rng/rng.c b/rng/rng.c
index 604de88..be9ca6f 100644
--- a/rng/rng.c
+++ b/rng/rng.c
@@ -148,6 +148,7 @@ gsl_rng_print_state (const gsl_rng * r)
 void
 gsl_rng_free (gsl_rng * r)
 {
+  if (!r) { return; }
   free (r->state);
   free (r);
 }
diff --git a/vector/init_source.c b/vector/init_source.c
index 7034f6d..6c62715 100644
--- a/vector/init_source.c
+++ b/vector/init_source.c
@@ -162,6 +162,7 @@ FUNCTION (gsl_vector, alloc_from_vector) (TYPE(gsl_vector) 
* w,
 void
 FUNCTION (gsl_vector, free) (TYPE (gsl_vector) * v)
 {
+  if (!v){ return; }
   if (v->owner)
     {
       FUNCTION(gsl_block, free) (v->block) ;
--
1.6.0.6.LR1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]