Sponsored Content
Top Forums Programming *** glibc detected *** double free or corruption: 0x40236ff4 *** Post 302196146 by g2wang on Friday 16th of May 2008 07:57:49 PM
Old 05-16-2008
Use reference in your member function

The problem seems to be your member function definition:
MyStack operator + (MyStack);
It should use a reference of MyStack as the argument as follows:
MyStack operator + (MyStack&);
Without the &, a copy of MyStack object is made and it contains a pointer to the private data member T* stackPtr. When the copy of the MyStack goes out of scope in the member function, the destructor of the MyStack object copy is called and the stackPtr is deleted. This also deletes the stackPtr of the original object because your class does not define a copy constructor to make a deep copy of the stackPtr. Then when your original object's destructor is called later, it does "delete [] stackPtr" again on an already deleted pointer. Thus the error appears.
 

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

Pointer to a struct (with pointers) *** glibc detected *** double free

I am using a structure defined as follows struct gene_square { double *x; double *y; };I have class, with a member function which is a pointer of this type: gene_square* m_Genes;I am allocating memory in the constructors like this: m_Genes = new gene_square; for (ii=0;... (1 Reply)
Discussion started by: jatoo
1 Replies

3. Programming

Why does this occur? *** glibc detected *** malloc(): memory corruption: 0x10013ff8 ***

there seems not to be error in this segment. In some computers, it can work well. But in others, it will give a failure. why it ocurrs and how to deal with it? in a function: if( *ver == NULL ) { *ver = (vertex *) malloc(sizeof(vertex)); //this line ... (17 Replies)
Discussion started by: cdbug
17 Replies

4. Programming

solved: glibc detection corruption using a fork in popen

Hi, I am having a hell of a time getting this to work. So basically, I have opened a popen to run a program that is going to prompt an action to occur half way through, when it gets to this I need to create a separate process and do some stuff, then return to the original process. This works... (0 Replies)
Discussion started by: imrank27
0 Replies

5. Programming

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

*** glibc detected *** ./a.out: malloc(): memory corruption (fast): Posted A minute ago M trying to make multiway tree and dont know what happend when this part of code get executed: 01void ins(NODE *ptr) 02{ 03 //working 04 if(ptr!=NULL) 05 { 06 SNODE *var=NULL; 07 var=(SNODE... (3 Replies)
Discussion started by: exgenome
3 Replies

6. 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

7. Programming

FORTRAN: double free or corruption

Hello. I'm looking for a quite "interesting" bug I'm using fortran 90, compiler gfortran and the main idea is for every time step I build a bin structure for search contact between particles, for this at the begining TYPE :: circle_index INTEGER(kind = 4) :: ind_p TYPE(circle_index),... (1 Reply)
Discussion started by: Marce
1 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
stooop(n)					    Simple Tcl Only Object Oriented Programming 					 stooop(n)

__________________________________________________________________________________________________________________________________________________

NAME
stooop - Object oriented extension. SYNOPSIS
package require Tcl 8.3 package require stooop ?4.4.1? ::stooop::class name body ::stooop::new class ?arg arg ...? ::stooop::delete object ?object ...? ::stooop::virtual proc name {this ?arg arg ...?} ?body? ::stooop::classof object ::stooop::new object ::stooop::printObjects ?pattern? ::stooop::record ::stooop::report ?pattern? _________________________________________________________________ DESCRIPTION
This package provides commands to extend Tcl in an object oriented manner, using a familiar C++ like syntax and behaviour. Stooop only introduces a few new commands: class, new, delete, virtual and classof. Along with a few coding conventions, that is basically all you need to know to use stooop. Stooop is meant to be as simple to use as possible. This manual is very succinct and is to be used as a quick reminder for the programmer, who should have read the thorough stooop_man.html HTML documentation at this point. ::stooop::class name body This command creates a class. The body, similar in contents to a Tcl namespace (which a class actually also is), contains member procedure definitions. Member procedures can also be defined outside the class body, by prefixing their name with class::, as you would proceed with namespace procedures. proc class {this ?arg arg ...?} ?base {?arg arg ...?} ...? body This is the constructor procedure for the class. It is invoked following a new invocation on the class. It must have the same name as the class and a first argument named this. Any number of base classes specifications, including arguments to be passed to their constructor, are allowed before the actual body of the procedure. proc ~class {this} body This is the destructor procedure for the class. It is invoked following a delete invocation. Its name must be the concatena- tion of a single ~ character followed by the class name (as in C++). It must have a single argument named this. proc name {this ?arg arg ...?} body This is a member procedure of the class, as its first argument is named this. It allows a simple access of member data for the object referenced by this inside the procedure. For example: set ($this,data) 0 proc name {?arg arg ...?} body This is a static (as in C++) member procedure of the class, as its first argument is not named this. Static (global) class data can be accessed as in: set (data) 0 proc class {this copy} body This is the optional copy procedure for the class. It must have the same name as the class and exactly 2 arguments named this and copy. It is invoked following a new invocation on an existing object of the class. ::stooop::new class ?arg arg ...? This command is used to create an object. The first argument is the class name and is followed by the arguments needed by the corre- sponding class constructor. A unique identifier for the object just created is returned. ::stooop::delete object ?object ...? This command is used to delete one or several objects. It takes one or more object identifiers as argument(s). ::stooop::virtual proc name {this ?arg arg ...?} ?body? The virtual specifier may be used on member procedures to achieve dynamic binding. A procedure in a base class can then be redefined (overloaded) in the derived class(es). If the base class procedure is invoked on an object, it is actually the derived class proce- dure which is invoked, if it exists. If the base class procedure has no body, then it is considered to be a pure virtual and the derived class procedure is always invoked. ::stooop::classof object This command returns the class of the existing object passed as single parameter. ::stooop::new object This command is used to create an object by copying an existing object. The copy constructor of the corresponding class is invoked if it exists, otherwise a simple copy of the copied object data members is performed. DEBUGGING
Environment variables STOOOPCHECKDATA Setting this variable to any true value will cause stooop to check for invalid member or class data access. STOOOPCHECKPROCEDURES Setting this variable to any true value will cause stooop to check for invalid member procedure arguments and pure interface classes instanciation. STOOOPCHECKALL Setting this variable to any true value will cause stooop to activate both procedure and data member checking. STOOOPCHECKOBJECTS Setting this variable to any true value will cause stooop to activate object checking. The following stooop namespace proce- dures then become available for debugging: printObjects, record and report. STOOOPTRACEPROCEDURES Setting this environment variable to either stdout, stderr or a file name, activates procedure tracing. The stooop library will then output to the specified channel 1 line of informational text for each member procedure invocation. STOOOPTRACEPROCEDURESFORMAT Defines the trace procedures output format. Defaults to "class: %C, procedure: %p, object: %O, arguments: %a". STOOOPTRACEDATA Setting this environment variable to either stdout, stderr or a file name, activates data tracing. The stooop library will then output to the specified channel 1 line of informational text for each member data access. STOOOPTRACEDATAFORMAT Defines the trace data output format. Defaults to "class: %C, procedure: %p, array: %A, object: %O, member: %m, operation: %o, value: %v". STOOOPTRACEDATAOPERATIONS When tracing data output, by default, all read, write and unsetting accesses are reported, but the user can set this variable to any combination of the letters r, w, and u for more specific tracing (please refer to the trace Tcl manual page for more information). STOOOPTRACEALL Setting this environment variable to either stdout, stderr or a file name, enables both procedure and data tracing. ::stooop::printObjects ?pattern? Prints an ordered list of existing objects, in creation order, oldest first. Each output line contains the class name, object iden- tifier and the procedure within which the creation occurred. The optional pattern argument (as in the Tcl string match command) can be used to limit the output to matching class names. ::stooop::record When invoked, a snapshot of all existing stooop objects is taken. Reporting can then be used at a later time to see which objects were created or deleted in the interval. ::stooop::report ?pattern? Prints the created and deleted objects since the ::stooop::record procedure was invoked last. If present, the pattern argument lim- its the output to matching class names. EXAMPLES
Please see the full HTML documentation in stooop_man.html. BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category stooop of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. KEYWORDS
C++, class, object, object oriented CATEGORY
Programming tools stooop 4.4.1 stooop(n)
All times are GMT -4. The time now is 06:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy