DAMAGE: after Normal block (#45)

M

Meghavvarnam

Hi all,

I just joined this group and am new to VC++. I wrote the code following
the next para in C++ and used VC++ 6.0 Enterprise Edition to build and
test.

I had the following error message because of an exception that gets
thrown when I call delete [] ipAddress; in the destructor -
~TrapDestination () :

"DAMAGE: after Normal block (#45)"

// ~~~~~~~~~~~
// plugIn.h
// ~~~~~~~~~~~
#include <memory>
#include <iostream>
#include <exception>
#include <assert.h>
using namespace std;

typedef char* pchar;

class TrapDestination {
private:
pchar ipAddress;
int port;
pchar communityName;
int snmpVersion;
pchar templateFileName;
void (*old_unexpected) ();

public:
TrapDestination () : ipAddress (NULL), communityName (NULL),
templateFileName (NULL) {
//old_unexpected = set_unexpected:):my_unexpected);
}
~TrapDestination () throw () {
cout << "TrapDestination Destructor" << endl;
if (ipAddress)
delete [] ipAddress;
if (communityName)
delete [] communityName;
if (templateFileName)
delete [] templateFileName;

//set_unexpected(old_unexpected); // restore org handler
if (uncaught_exception())
cout << "uncaught_exception() is TRUE" << endl;
else
cout << "uncaught_exception() is FALSE" << endl;
}

char *getIPAddress () throw () { return ipAddress; }
int getPort () throw () { return port; }
char *getcommunityName () throw () { return communityName; }
int getsnmpVersion () throw () { return snmpVersion; }
char *gettemplateFileName () throw () { return templateFileName; }

void setIPAddress (char *ipAddr="") throw () {
ipAddress = (pchar) new char(strlen (ipAddr) + 1);
if (ipAddress)
strcpy (ipAddress, ipAddr);
}

void setPort (int aPort=162) { port = aPort; }

void setcommunityName (char *aCommunityName="public") {
communityName = (pchar) new char (strlen (aCommunityName) + 1);
if (communityName)
strcpy (communityName, aCommunityName);
}

void setsnmpVersion (int snmpVer=2) { snmpVersion = snmpVer; }

void settemplateFileName (char *templFileName="") {
templateFileName = (pchar) new char (strlen (templFileName) + 1);
if (templateFileName)
strcpy (templateFileName, templFileName);
}
};


class SnmpTrapGen {
private:
char *ipAddress;
int port;
char *community;
int snmpVersion;
public:
SnmpTrapGen (char *ipAddress=NULL, int port=162, char
*community="public", int snmpVersion=2){
}
~SnmpTrapGen () {
if (ipAddress)
delete [] ipAddress;
if (community)
delete [] community;
}

sendTrap (char *alertToSend);

char *getIPAddress () { return ipAddress; }
int getPort () { return port; }
char *getcommunity () { return community; }
int getsnmpVersion () { return snmpVersion; }

void setIPAddress (char *ipAddr="") {
ipAddress = new char (strlen (ipAddr) + 1);
if (ipAddress)
strcpy (ipAddress, ipAddr);
}
void setPort (int aPort=162) { port = aPort; }
void setcommunity (char *aCommunity="public") {
community = new char (strlen (aCommunity) + 1);
if (community)
strcpy (community, aCommunity);
}
void setsnmpVersion (int snmpVer=2) { snmpVersion = snmpVer; }
};

// ~~~~~~~~~~~~
// plugIn.cpp
// ~~~~~~~~~~~~

#include "net-snmp\net-snmp-config.h"
#include "net-snmp\net-snmp-includes.h"
#include "plugIn.h"

void local_terminator() {
cout << "terminate called local_terminator !!!" << endl;
exit(1);
}

void (*old_terminate)();

void my_unexpected () {
// This cannot return - instead it can either call std::terminate() or
throw an exception

cout << "Am in my_unexpected " << endl;
}

int main (int argc, char **argv) {
try {
TrapDestination td;

old_terminate = set_terminate(local_terminator);

td.setIPAddress ("127.0.0.1");
td.setcommunityName ();
td.settemplateFileName ("tempname");
cout << "IP address = " << td.getIPAddress () << endl;
printf ("communityName = %s.\n", td.getcommunityName ());
printf ("templateFileName = %s.\n", td.gettemplateFileName ());
return 0;
} catch (bad_exception const &) {
printf("Caught bad_exception\n"); // though such an exception was
never thrown
return 0;
} catch (...) {
cout << "Inside main's catch all" << endl;
return 0;
}
}

Any light on :

1. Why is delete causing this exception to be thrown could be helpful.
2. What the solution for this is.

will be great!

Thank you,
Meghavvarnam Satish
 
C

Chris Dollin

Meghavvarnam said:
Hi all,

I just joined this group and am new to VC++. I wrote the code following
the next para in C++ and used VC++ 6.0 Enterprise Edition to build and
test.

Erm cough, this newsgroup is comp.lang.c, not comp.lang.c++, as ten million
other posters will likely tell you.
 
M

Martin Ambuhl

Meghavvarnam said:
Hi all,

I just joined this group and am new to VC++. I wrote the code following
the next para in C++ and used VC++ 6.0 Enterprise Edition to build and
test.

For questions about C++, vist comp.lang.c++. C and C++ are different
languages.
For questions about VC++, visit one of the microsoft.public.vc.*
newsgroups, perhaps microsoft.public.vc.onlinw_help.

comp.lang.c deals only in the standard C programming language, that
means that other languages (such as C++) are off-topic as are the quirks
of a particular implementation like VC++. Before posting in newsgroups
like the ones I mentioned above (and in comp.lang.c), you should follow
the newsgroup and check the FAQ. Good luck with your adventure into C++.

Note that the standard C++ header is said:
#include "net-snmp\net-snmp-config.h"
#include "net-snmp\net-snmp-includes.h"
are not standard C++. That means that your questions will be off-topic
in comp.lang.c++ as well. Stick to the microsoft newsgroups or, if you
want to post to comp.lang.C++, produce a *small* program that reproduces
your problem without using non-standard extensions.
 
M

Meghavvarnam

Hi again:

Ok folks. I apologize for posting on the wrong group. Am sorry.

I have posted now on comp.lang.c++. The includes :
#include "net-snmp\net-snmp-config.h"
#include "net-snmp\net-snmp-includes.h"

do not effect the behaviour.

I have commented the two lines, built and tested just before responding
here. The same problem persists.

Thank you folks any way. And please accept my apologies.

Regards,
Megh
 
C

CBFalconer

Meghavvarnam said:
I just joined this group and am new to VC++. I wrote the code
following the next para in C++ and used VC++ 6.0 Enterprise
Edition to build and test.

I had the following error message because of an exception that
gets thrown when I call delete [] ipAddress; in the destructor -
~TrapDestination () :

"DAMAGE: after Normal block (#45)"

// ~~~~~~~~~~~
// plugIn.h
// ~~~~~~~~~~~
#include <memory>
#include <iostream>
#include <exception>
#include <assert.h>
using namespace std;

You have a whole herd of misconceptions. First, this is not a
group, and you don't join it. It is a usenet newsgroup and is
distributed all over the world. Second, it has nothing to do with
google, except they keep a copy of the traffic and provide a
horribly broken interface to the system.

Third, this newsgroup deals with C, not C++. The languages are
different, and each has its own newsgroup(s). C++ is off-topic
here on c.l.c.

Before posting to a newsgroup you should monitor its traffic for a
reasonable period, and read any FAQs associated with it. That way
you will have an idea of the subject under discussion, and may
avoid posing unnecessary (because answered in the FAQ) questions.

--
Some informative links:
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top