bugGNU Scientific Library - Bugs: bug #27194, found a bug in ode-initval/rk4.c

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #27194: found a bug in ode-initval/rk4.c

Submitter:  Ettl Martin <ettlmartin>
Submitted:  Thu 06 Aug 2009 09:45:14 PM UTC
   
 
Category:  Runtime error Severity:  3 - Normal
Operating System:  all Status:  Fixed
Assigned to:  None Open/Closed:  Closed
Release:  1.9

Wed 12 Aug 2009 03:48:45 PM UTC, comment #1: 

fixed by a9131698df8f744f8ab38d7458745f541c2ff2c7

-Deleted Account- <bjg>
Thu 06 Aug 2009 09:45:14 PM UTC, original submission:  

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

Ettl Martin <ettlmartin>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by ettlmartin (Submitted the item)
  •  

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-08-12 bjg StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2009-08-12 bjg StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code