I have sample code below. The ServantI.cpp:login method, it construct a New UserContext. Before context is returned, it is assigned to new Session's sessionContext field, which is UserContext*;
//idl:
struct UserContext{
string name;
string ipaddress;
string ssoToken;
};
UserContext login(in string name, in string cipher) raises (AuthenticationException);
void logout(in string name);
// servantI.cpp
::project::UserContext * servantI::login (
const char * name,
const char * cipher)
{
project::UserContext* context = new UserConytext(); ...
boost::shared_ptr<Session> session(new Session(name, context));
map.addSession(name, session);
return context;
}
void servantI::logout (const char * name)
{
map.remove(name);
}
//Session.h:
class Session
{
std::string _username;
UserContext* _sessionContext;
public:
Session(string name, UserContext* context){ _sessionContext = context; ..}
virtual ~Session(void){
cout<<"Call descrutction "<<endl;
}
}
My question is whether there is memory leakage in Session Class since there is place to free _sessionContext pointer. It is also report run-time unhandle exception if I change
UserContext* _sessionContext;
to
UserContext_var _sessionContext;
in class Session