[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Simulavr-devel] [PATCH 06/13] Fix for memory leak in Pin class
From: |
Onno Kortmann |
Subject: |
[Simulavr-devel] [PATCH 06/13] Fix for memory leak in Pin class |
Date: |
Tue, 3 Mar 2009 23:46:09 +0100 |
When using the pins alot, the lost memory may add up
quite a bit.
Signed-off-by: Onno Kortmann <address@hidden>
---
src/pin.cpp | 16 ++++++++++++++--
src/pin.h | 11 ++++++++---
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/src/pin.cpp b/src/pin.cpp
index 184ae04..79beb21 100644
--- a/src/pin.cpp
+++ b/src/pin.cpp
@@ -82,7 +82,9 @@ void Pin::SetInState ( const Pin &p) {
Pin::Pin(T_Pinstate ps) {
pinOfPort=0;
- connectedTo=new MirrorNet(this);
+ connectedTo=new MirrorNet(this);
+ myNet=true;
+
outState=ps;
switch (ps) {
@@ -107,16 +109,25 @@ Pin::Pin(T_Pinstate ps) {
Pin::Pin() {
pinOfPort=0;
- connectedTo= new MirrorNet(this);
+ connectedTo= new MirrorNet(this);
+ myNet=true;
+
outState=TRISTATE;
analogValue=INT_MAX/2;
//ui=0;
}
+Pin::~Pin() {
+ if (myNet)
+ delete connectedTo;
+}
+
Pin::Pin( unsigned char *parentPin, unsigned char _mask) {
pinOfPort=parentPin;
mask=_mask;
connectedTo=new MirrorNet(this);
+ myNet=true;
+
outState=TRISTATE;
analogValue=INT_MAX;
}
@@ -133,6 +144,7 @@ void Pin::RegisterNet(Net *n) {
}
connectedTo=n;
+ myNet=false;
}
Pin::operator unsigned char() const {
diff --git a/src/pin.h b/src/pin.h
index 078d8b6..eb38595 100644
--- a/src/pin.h
+++ b/src/pin.h
@@ -44,7 +44,11 @@ class Pin {
unsigned char mask;
int analogValue;
- NetInterface *connectedTo;
+ NetInterface *connectedTo;
+
+ /*! iff mynet is true, the NetInterface connectedTo belongs to this
+ PIN and must be memory-managed by this PIN! */
+ bool myNet;
public:
Pin(const OpenDrain &od);
@@ -70,7 +74,7 @@ class Pin {
public:
void SetOutState( T_Pinstate s);
virtual void SetInState ( const Pin &p);
-
+
Pin(T_Pinstate ps);
Pin();
Pin( unsigned char *parentPin, unsigned char mask);
@@ -83,7 +87,7 @@ class Pin {
#endif
virtual void RegisterNet(Net *n);
virtual Pin GetPin() { return *this;}
- virtual ~Pin(){}
+ virtual ~Pin();
//T_Pinstate GetOutState();
int GetAnalog() const;
void RegisterCallback( HasPinNotifyFunction *);
@@ -94,6 +98,7 @@ class Pin {
};
+
class ExtPin : public Pin, public ExternalType {
protected:
UserInterface *ui;
--
1.5.6.5
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Simulavr-devel] [PATCH 06/13] Fix for memory leak in Pin class,
Onno Kortmann <=