URL:
<http://savannah.gnu.org/bugs/?27194>
Summary: found a bug in ode-initval/rk4.c
Project: GNU Scientific Library
Submitted by: ettlmartin
Submitted on: Thu 06 Aug 2009 21:45:14 GMT
Category: Runtime error
Severity: 3 - Normal
Operating System: all
Status: None
Assigned to: None
Open/Closed: Open
Release: 1.9
Discussion Lock: Any
_______________________________________________________
Details:
Hello,
i have checked the sources of gsl-1.9 with the static code analysis tool
cppcheck. It found an issue in file /ode-initval/rk4.c at line 72.
Take a look at the source:
static void *
rk4_alloc (size_t dim)
{
rk4_state_t *state = (rk4_state_t *) malloc (sizeof (rk4_state_t));
....
state->k = (double *) malloc (dim * sizeof (double));
.....
state->k1 = (double *) malloc (dim * sizeof (double));
if (state->k1 == 0)
{
72 free (state);
free (state->k);
GSL_ERROR_NULL ("failed to allocate space for k1", GSL_ENOMEM);
}
As you can see, the memory of state is freed BEFORE state->k. This can lead
to an runntime error.
A possible way out is reordering the free statements:
static void *
rk4_alloc (size_t dim)
{
rk4_state_t *state = (rk4_state_t *) malloc (sizeof (rk4_state_t));
....
state->k = (double *) malloc (dim * sizeof (double));
.....
state->k1 = (double *) malloc (dim * sizeof (double));
if (state->k1 == 0)
{
72 free (state->k);
free (state);
GSL_ERROR_NULL ("failed to allocate space for k1", GSL_ENOMEM);
}
....
Best regards
Ettl Martin
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?27194>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
_______________________________________________
Bug-gsl mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-gsl