[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gsl] Invalid memory accesses in gsl-1.6/vector/test.c
From: |
Julian Seward |
Subject: |
[Bug-gsl] Invalid memory accesses in gsl-1.6/vector/test.c |
Date: |
Tue, 5 Jul 2005 16:41:03 +0100 |
User-agent: |
KMail/1.8.1 |
Hi. I'm a developer of Valgrind (http://www.valgrind.org), a GPL'd
suite of memory debugging/profiling tools.
I've been using gsl-1.5 for a while as an excellent source of test
cases for Valgrind's CPU simulation. I recently changed to gsl-1.6
and got a large number of complaints from valgrind about vector/test,
which I just looked into.
The impression I get is that there's some double-freeing going on
in this test, leading to a huge number of accesses to freed
memory. I tried to cut it down to the attached program, but
there are so many layers of macros that I find it hard to make
sense of.
Is this a known problem? Has anyone [apart from me] run the gsl-1.6
test suite though a memory debugging tool like Valgrind or Purify?
J
// Hacked version of vector/test.c showing the problem. I get three
// reports of double frees and three of reads of freed
// memory when running on valgrind.
/* vector/test.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman, Brian Gough
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#if !GSL_RANGE_CHECK
#undef GSL_RANGE_CHECK
#define GSL_RANGE_CHECK 1
#endif
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_test.h>
#include <gsl/gsl_ieee_utils.h>
int status = 0;
#ifndef DESC
#define DESC ""
#endif
#define BASE_DOUBLE
#include "templates_on.h"
/* vector/test_source.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman, Brian Gough
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
void FUNCTION (test, func) (size_t stride, size_t N);
void FUNCTION (test, ops) (size_t stride1, size_t stride2, size_t N);
void FUNCTION (test, file) (size_t stride, size_t N);
void FUNCTION (test, text) (size_t stride, size_t N);
void FUNCTION (test, trap) (size_t stride, size_t N);
TYPE (gsl_vector) * FUNCTION(create, vector) (size_t stride, size_t N);
#define TEST(expr,desc) gsl_test((expr), NAME(gsl_vector) desc " stride=%d,
N=%d", stride, N)
#define TEST2(expr,desc) gsl_test((expr), NAME(gsl_vector) desc " stride1=%d,
stride2=%d, N=%d", stride1, stride2, N)
TYPE (gsl_vector) *
FUNCTION(create, vector) (size_t stride, size_t N)
{
TYPE (gsl_vector) * v = FUNCTION (gsl_vector, calloc) (N*stride);
v->stride = stride;
v->size = N;
return v;
}
void
FUNCTION (test, func) (size_t stride, size_t N)
{
TYPE (gsl_vector) * v0;
TYPE (gsl_vector) * v;
QUALIFIED_VIEW(gsl_vector,view) view;
size_t i, j;
if (stride == 1)
{
v = FUNCTION (gsl_vector, alloc) (N);
TEST(v->data == 0, "_alloc pointer");
TEST(v->size != N, "_alloc size");
TEST(v->stride != 1, "_alloc stride");
FUNCTION (gsl_vector, free) (v); /* free whatever is in v */
}
FUNCTION (gsl_vector, free) (v0); /* free whatever is in v */
}
#include "templates_off.h"
#undef BASE_DOUBLE
void my_error_handler (const char *reason, const char *file,
int line, int err);
int
main (void)
{
size_t stride, ostride, N;
{ N= 10;
{
stride=1;
printf("N = %d, stride = %d\n", N, stride);
test_func (stride, N);
}
}
return 0;
}
- [Bug-gsl] Invalid memory accesses in gsl-1.6/vector/test.c,
Julian Seward <=