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
-- 
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02


_______________________________________________
Bug-gsl mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-gsl

Reply via email to