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

Submitted by:  Ettl Martin <ettlmartin>
Submitted on:  Thu 06 Aug 2009 09:45:14 PM UTC  
 
Category: Runtime errorSeverity: 3 - Normal
Operating System: allStatus: Fixed
Assigned to: NoneOpen/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>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 12 Aug 2009 03:48:44 PM UTCbjgStatusConfirmed=>Fixed
      Open/ClosedOpen=>Closed
    Wed 12 Aug 2009 03:39:29 PM UTCbjgStatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup1