Sponsored Content
Top Forums Programming Pointer to a struct (with pointers) *** glibc detected *** double free Post 302263166 by jatoo on Monday 1st of December 2008 02:08:15 AM
Old 12-01-2008
Pointer to a struct (with pointers) *** glibc detected *** double free

I am using a structure defined as follows

Code:
struct gene_square
{
    double *x;
    double *y;
};

I have class, with a member function which is a pointer of this type:

Code:
gene_square* m_Genes;

I am allocating memory in the constructors like this:

Code:
m_Genes = new gene_square[square_genome_size];
    for (ii=0; ii<square_genome_size; ii++)
    {
        (m_Genes+ii)->x = new double[POINTS];
        (m_Genes+ii)->y = new double[POINTS];
    }

And my destructor does this:

Code:
if(m_Genes != NULL)
    {
        for(ii=0; ii<square_genome_size; ii++)
        {
            if (((m_Genes+ii)->x)!=NULL)
            {
                delete [] (m_Genes+ii)->x;
            }
            if (((m_Genes+ii)->y)!= NULL)
            {    
                delete [] (m_Genes+ii)->y;
            }
        }
        delete [] m_Genes;
    }

But when the destructor is called I am getting a glibc double free error.

Code:
*** glibc detected *** ./Evolution: double free or corruption (fasttop): 0x08055008 ***

And I can't work it out.

Anyone able to help?
 

10 More Discussions You Might Find Interesting

1. Programming

*** glibc detected *** free(): invalid next size (normal): 0x0000000000503e70 ***

hi, I have made a small C program that make use of malloc and free for processing bitmap images. when i try to run the program, I am getting a error something like *** glibc detected *** free(): invalid next size (normal): 0x0000000000503e70 *** I am not sure of which free() is causing this... (1 Reply)
Discussion started by: vbreddy
1 Replies

2. Programming

*** glibc detected *** double free or corruption: 0x40236ff4 ***

when i try to use the class i wrote, i either get this: *** glibc detected *** double free or corruption: 0x40236ff4 *** and the proccess exits with an error code of 0; or it segfaults. could someone look at my header file (with imp.) to give me some insight as to why its not working? ... (19 Replies)
Discussion started by: norsk hedensk
19 Replies

3. Homework & Coursework Questions

C++ struct pointers & functions

Hi All, My latest assignment (practice not coursework!) is to write prototype interactive exam/test console application. I've used structs to store the question information (not sure if this was the best way to do it?) and I have the following code that outputs each question and it's possible... (0 Replies)
Discussion started by: pondlife
0 Replies

4. Homework & Coursework Questions

Passing pointers to struct

Hi, i'm trying to copy a struct into a binary file using the unix instruction write, so i declare and fill the struct "superbloque" in one function "initSB" and then i pass the pointer to another function called bwrite (for block write) which calls write. The problem is that i call the function... (2 Replies)
Discussion started by: ignatius3
2 Replies

5. Programming

Using pointers to struct members as args to functions

In a well-known book on the C language, there is an example of an efficient method for using a struct member as an argument to a function. (I'm a C noob, but I believe the correct terminology might be: use call-by-reference instead of call-by-value.) The function is printf. Anyway, here's a... (5 Replies)
Discussion started by: uiop44
5 Replies

6. Programming

Pointer to pointers

Hi guys, I'm trying to understand pointers in C and made a simple example and I've problems with It. Can someone help? #include <stdio.h> #include <stdlib.h> #include <assert.h> int f1(char **str_); int main(int argc, char **argv) { char *str = NULL; f1(&str); ... (3 Replies)
Discussion started by: pharaoh
3 Replies

7. Programming

*** glibc detected *** : malloc(): memory corruption (fast)

Hi Friends, while executing the below code, am getting *** glibc detected *** ./ok: malloc(): memory corruption (fast) error, please suggest how to solve this issue. #include <stdio.h> #include <string.h> #include <sqlca.h> #include <alloca.h> /* Define constants for VARCHAR... (2 Replies)
Discussion started by: mpjobsrch
2 Replies

8. Programming

*** glibc detected *** ./a.out malloc() memory corruption

I am facing a problem of memory corruption. The loop runs for the first time but does not go through the second time. What could be the problem? for(int z=0;z<2;z++) { fp=fopen("poly.dat","r"); /*do something which reads this file into a 2D array*/ fclose(fp); ... (10 Replies)
Discussion started by: dare
10 Replies

9. Programming

C++ glibc detected double free or corruption(!prev) using shared library

Currently I test a shared library vendor provided in linux , the following is the simple source : #include <iostream> using namespace std; extern int test1(); extern int test2(); int main() { cout << "hello world" << endl ; return 0 ; cout << "Test 1" << endl; ... (6 Replies)
Discussion started by: barfatchen
6 Replies

10. Homework & Coursework Questions

FORTRAN error *** glibc detected ***

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I'm doing aproximation of derivative called five-point stencil. For every value of x, in interval , in step... (0 Replies)
Discussion started by: antonija
0 Replies
Tcl_DoubleObj(3)					      Tcl Library Procedures						  Tcl_DoubleObj(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_NewDoubleObj, Tcl_SetDoubleObj, Tcl_GetDoubleFromObj - manipulate Tcl objects as floating-point values SYNOPSIS
#include <tcl.h> Tcl_Obj * Tcl_NewDoubleObj(doubleValue) Tcl_SetDoubleObj(objPtr, doubleValue) int Tcl_GetDoubleFromObj(interp, objPtr, doublePtr) ARGUMENTS
double doubleValue (in) A double-precision floating point value used to initialize or set a double object. Tcl_Obj *objPtr (in/out) For Tcl_SetDoubleObj, this points to the object to be converted to double type. For Tcl_GetDoubleFro- mObj, this refers to the object from which to get a double value; if objPtr does not already point to a double object, an attempt will be made to convert it to one. Tcl_Interp *interp (in/out) If an error occurs during conversion, an error message is left in the interpreter's result object unless interp is NULL. double *doublePtr (out) Points to place to store the double value obtained from objPtr. _________________________________________________________________ DESCRIPTION
These procedures are used to create, modify, and read double Tcl objects from C code. Tcl_NewDoubleObj and Tcl_SetDoubleObj will create a new object of double type or modify an existing object to have double type. Both of these procedures set the object to have the double- precision floating point value given by doubleValue; Tcl_NewDoubleObj returns a pointer to a newly created object with reference count zero. Both procedures set the object's type to be double and assign the double value to the object's internal representation doubleValue member. Tcl_SetDoubleObj invalidates any old string representation and, if the object is not already a double object, frees any old inter- nal representation. Tcl_GetDoubleFromObj attempts to return a double value from the Tcl object objPtr. If the object is not already a double object, it will attempt to convert it to one. If an error occurs during conversion, it returns TCL_ERROR and leaves an error message in the interpreter's result object unless interp is NULL. Otherwise, it returns TCL_OK and stores the double value in the address given by doublePtr. If the object is not already a double object, the conversion will free any old internal representation. SEE ALSO
Tcl_NewObj, Tcl_DecrRefCount, Tcl_IncrRefCount, Tcl_GetObjResult KEYWORDS
double, double object, double type, internal representation, object, object type, string representation Tcl 8.0 Tcl_DoubleObj(3)
All times are GMT -4. The time now is 06:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy