From 51427930acb319dcc3c68725eebd6d0cdef3a486 Mon Sep 17 00:00:00 2001 From: rahuel Date: Thu, 14 Apr 2005 11:32:21 +0000 Subject: [PATCH] Memory Leaks + Traces --- src/GraphBase/DataFlowBase_DataPort.cxx | 83 ++++++++++++++++++++----- src/GraphBase/DataFlowBase_DataPort.hxx | 3 +- 2 files changed, 71 insertions(+), 15 deletions(-) diff --git a/src/GraphBase/DataFlowBase_DataPort.cxx b/src/GraphBase/DataFlowBase_DataPort.cxx index 9aac0d3..c2f9e8f 100644 --- a/src/GraphBase/DataFlowBase_DataPort.cxx +++ b/src/GraphBase/DataFlowBase_DataPort.cxx @@ -114,6 +114,7 @@ void GraphBase::DataPort::Value( const CORBA::Any & aDataValue ) { Value( aValue ) ; } +#define ValueTrace 0 void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { // cdebug << pthread_self() << " Value(aDataValue) --> pthread_mutex_lock " << &_MutexWait // << endl ; @@ -130,17 +131,23 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { // const char * Type = _Type.c_str() ; const char * Type = GetServicesParameter().Parametertype ; _Value = &_theValue ; +#if ValueTrace cdebug << "NewValue " << NodeName() << " " << PortName() << " " << PortType() << " : " << aDataValue << " kind " << aDataValue->type()->kind() << " " ; +#endif switch (aDataValue->type()->kind()) { // Input Value case CORBA::tk_string: { // Input string Value char * t; *aDataValue >>= t; +#if ValueTrace cdebug << t << " (string)" ; +#endif if ( !strcmp( Type , "string" ) ) { // SuperVision Value _theValue = aDataValue ; *_theValue >>= t; +#if ValueTrace cdebug << " == Value( " << t << ") (string)"; +#endif } else { CORBA::Any * theValue = new CORBA::Any() ; @@ -150,14 +157,18 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { sscanf( t , "%ld" , &l ) ; *theValue <<= l ; *theValue >>= l; +#if ValueTrace cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ; +#endif } else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { double d ; sscanf( t , "%lf" , &d ) ; *theValue <<= d ; *theValue >>= d; +#if ValueTrace cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ; +#endif } else { // Default CORBA::Object_ptr ObjRef ; @@ -169,8 +180,10 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { *theValue <<= CORBA::Object::_nil() ; } *theValue >>= ObjRef ; +#if ValueTrace cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind " << theValue->type()->kind() ; +#endif } _theValue = theValue ; *_Value = theValue ; @@ -182,13 +195,17 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { case CORBA::tk_long: { // Input long Value long l; *aDataValue >>= l; +#if ValueTrace cdebug << "Value( " << l << ") (long)"; +#endif if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) || !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) { // SuperVision Value _theValue = aDataValue ; *_Value = aDataValue ; *_theValue >>= l; +#if ValueTrace cdebug << " == Value( " << l << ") (long)"; +#endif } else { CORBA::Any * theValue = new CORBA::Any() ; @@ -198,20 +215,26 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { *theValue <<= t ; char *tt ; *theValue >>= tt ; +#if ValueTrace cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ; +#endif } else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { double d = l ; *theValue <<= d ; *theValue >>= d ; +#if ValueTrace cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ; +#endif } else { // Default CORBA::Object_ptr ObjRef ; *theValue <<= CORBA::Object::_nil() ; *theValue >>= ObjRef ; +#if ValueTrace cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind " << theValue->type()->kind() ; +#endif } _theValue = theValue ; *_Value = theValue ; @@ -223,12 +246,16 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { case CORBA::tk_double: { // Input double Value double d; *aDataValue >>= d; +#if ValueTrace cdebug << "Value( " << d << ") (double)"; +#endif if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { // SuperVision Value _theValue = aDataValue ; *_Value = aDataValue ; *_theValue >>= d; +#if ValueTrace cdebug << " == Value( " << d << ") (double)"; +#endif } else { CORBA::Any * theValue = new CORBA::Any() ; @@ -238,21 +265,27 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { *theValue <<= t ; char *tt ; *theValue >>= tt ; +#if ValueTrace cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ; +#endif } else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) || !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) { long l = (long ) d ; *theValue <<= l ; *theValue >>= l; +#if ValueTrace cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ; +#endif } else { // Default CORBA::Object_ptr ObjRef ; *theValue <<= CORBA::Object::_nil() ; *theValue >>= ObjRef ; +#if ValueTrace cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind " << theValue->type()->kind() ; +#endif } _theValue = theValue ; *_Value = theValue ; @@ -264,7 +297,9 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { case CORBA::tk_objref: { // Input objref Value CORBA::Object_ptr obj ; *aDataValue >>= obj; +#if ValueTrace cdebug << "Value( " << ObjectToString( obj ) << ") (object reference)"; +#endif if ( strcmp( Type , "string" ) && strcmp( Type , "boolean" ) && strcmp( Type , "char" ) && strcmp( Type , "short" ) && strcmp( Type , "long" ) && @@ -272,27 +307,35 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { _theValue = aDataValue ; *_Value = aDataValue ; *_theValue >>= obj; +#if ValueTrace cdebug << " == Value( " << ObjectToString( obj ) << ") (object reference)"; +#endif } else { CORBA::Any * theValue = new CORBA::Any() ; if ( !strcmp( Type , "string" ) ) { *theValue <<= ObjectToString( obj ) ; *theValue >>= obj ; +#if ValueTrace cdebug << " --> Value( " << ObjectToString( obj ) << ") (string) kind " << theValue->type()->kind() ; +#endif } else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) || !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) { long l = (long ) obj ; *theValue <<= l ; *theValue >>= l; +#if ValueTrace cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ; +#endif } else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { double d = (double ) 0. ; *theValue <<= d ; *theValue >>= d; +#if ValueTrace cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ; +#endif } _theValue = theValue ; *_Value = theValue ; @@ -307,7 +350,9 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { break; } } +#if ValueTrace cdebug << endl ; +#endif if ( pthread_mutex_unlock( &_MutexWait ) ) { perror( "unlock DataValue" ) ; exit( 0 ) ; @@ -317,7 +362,9 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { } -CORBA::Any const * GraphBase::DataPort::Value() const { +// PAL8506 +//JR 30.03.2005 Memory Leak + Debug(crash) CORBA::Any const * GraphBase::DataPort::Value() const { +const CORBA::Any GraphBase::DataPort::Value() const { pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ; // cdebug << pthread_self() << " Value() --> pthread_mutex_lock " << aMutexWait << endl ; if ( pthread_mutex_lock( aMutexWait ) ) { @@ -326,7 +373,8 @@ CORBA::Any const * GraphBase::DataPort::Value() const { } // cdebug << pthread_self() << " Value() --> pthread_mutex_locked " << aMutexWait << endl ; const CORBA::Any *const Value = *_Value ; - CORBA::Any * theValue ; +//JR 30.03.2005 CORBA::Any * theValue ; + CORBA::Any theValue ; // cdebug << pthread_self() << " Value " << NodeName() << " " << PortName() << " " // << PortType() << " _Value " << _Value << " *_Value " << *_Value << " Value->type " // << Value->type() ; @@ -338,23 +386,28 @@ CORBA::Any const * GraphBase::DataPort::Value() const { } if ( PortDone() ) { //JR 21.02.2005 Debug Memory leak : theValue = new CORBA::Any( *Value ) ; - theValue = (CORBA::Any * ) Value ; - switch ( theValue->type()->kind() ) { +//JR 30.03.2005 theValue = (CORBA::Any * ) Value ; + theValue = *Value ; +//JR 30.03.2005 switch ( theValue->type()->kind() ) { + switch ( theValue.type()->kind() ) { case CORBA::tk_string: { char * t; - *theValue >>= t; +//JR 30.03.2005 *theValue >>= t; + theValue >>= t; // cdebug << "GraphBase::DataPort::Value() : " << t << " (string) " << endl ; break; } case CORBA::tk_double: { double d; - *theValue >>= d; +//JR 30.03.2005 *theValue >>= d; + theValue >>= d; // cdebug << "GraphBase::DataPort::Value() : " << d << " (double) " << endl ; break; } case CORBA::tk_long: { long l; - *theValue >>= l; +//JR 30.03.2005 *theValue >>= l; + theValue >>= l; // cdebug << "GraphBase::DataPort::Value() : " << l << " (long) " << endl ; break; } @@ -362,7 +415,8 @@ CORBA::Any const * GraphBase::DataPort::Value() const { CORBA::Object_ptr obj ; char * retstr ; try { - *theValue >>= obj ; +//JR 30.03.2005 *theValue >>= obj ; + theValue >>= obj ; retstr = ObjectToString( obj ); // cdebug << "GraphBase::DataPort::Value() : " << retstr // << "(object reference) " << endl; @@ -382,7 +436,8 @@ CORBA::Any const * GraphBase::DataPort::Value() const { else { // cdebug << "GraphBase::DataPort::InitialValue() " << endl ; //JR 21.02.2005 Debug Memory leak : theValue = new CORBA::Any( *Value ) ; - theValue = (CORBA::Any * ) Value ; +//JR 30.03.2005 theValue = (CORBA::Any * ) Value ; + theValue = *Value ; } if ( pthread_mutex_unlock( aMutexWait ) ) { perror( "unlock DataValue" ) ; @@ -421,14 +476,14 @@ bool GraphBase::DataPort::BoolValue() const { perror( "unlock DataValue" ) ; exit( 0 ) ; } - cdebug << pthread_self() << " " << NodeName() << "( " << PortName() << " ) BoolValue " << RetVal << endl ; +// cdebug << pthread_self() << " " << NodeName() << "( " << PortName() << " ) BoolValue " << RetVal << endl ; return RetVal ; } void GraphBase::DataPort::StringValue(ostream & f ) const { pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ; -// cdebug << pthread_self() << " StringValue() --> pthread_mutex_lock " << aMutexWait -// << endl ; +// cdebug_in << pthread_self() << " StringValue() --> pthread_mutex_lock " << aMutexWait +// << endl ; if ( pthread_mutex_lock( aMutexWait ) ) { perror( "lock DataValue" ) ; exit( 0 ) ; @@ -478,8 +533,8 @@ void GraphBase::DataPort::StringValue(ostream & f ) const { perror( "unlock DataValue" ) ; exit( 0 ) ; } -// cdebug << pthread_self() << " StringValue() --> pthread_mutex_unlocked " << aMutexWait -// << endl ; +// cdebug_out << pthread_self() << " StringValue() --> pthread_mutex_unlocked " << aMutexWait +// << endl ; } diff --git a/src/GraphBase/DataFlowBase_DataPort.hxx b/src/GraphBase/DataFlowBase_DataPort.hxx index d15f029..89bf02a 100644 --- a/src/GraphBase/DataFlowBase_DataPort.hxx +++ b/src/GraphBase/DataFlowBase_DataPort.hxx @@ -61,7 +61,8 @@ namespace GraphBase { void Value (const CORBA::Any & aValue ) ; // void Value( const CORBA::Any * aValue ) ; // void Value( const CORBA::Any ** aValue ) ; - CORBA::Any const * Value() const ; +// CORBA::Any const * Value() const ; + const CORBA::Any Value() const ; bool BoolValue() const ; // const CORBA::Any ** ValuePtr() const ; -- 2.39.2