bug-gsl
[Top][All Lists]
Advanced

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

[Bug-gsl] [bug #27194] found a bug in ode-initval/rk4.c


From: Ettl Martin
Subject: [Bug-gsl] [bug #27194] found a bug in ode-initval/rk4.c
Date: Thu, 06 Aug 2009 21:45:15 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.12) Gecko/2009070811 Ubuntu/9.04 (jaunty) Firefox/3.0.12

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/





reply via email to

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