This has been a cool week, not the weather though, because I managed to solve problems instead of creating more. Thanks to Dr. Shawn’s suggestion, I’ve started using valgrind to test my code. It turns out to be such a gem. Not having the proper fundamentals, I didn’t know such a thing actually existed.

Testing out Valgrind

There were so many instances where I spent hours trying to discover segmentation fault in my application. Seg fault is even harder to trace when the debugging log is lacking. With valgrind, I can actually see what is actually causing the crash, and most importantly, it points to the line of code or at least narrows it down to a function.

So few days ago, I was having this frustrating problem of seg fault suddenly appearing out of nowhere, after new user registration. Since I was specializing some of the AuthWidget functions, I didn’t know if it was my part of the code or the AuthWidget library causing the problems. And… obviously, it was my code. I was deleting an uninitialized variable, and Valgrind spotted it out immediately.

Another Segmentation Fault Error

I was having seg fault consistently 10 minutes after I run my application because the user session happens to be deleted.

The problem was because I was passing a pointer to the Wt::Dbo::Session initialized in the User Login into my Main WApplication. I thought this way, I could still retain the Session information such as login status.

Little did I know that, after 10 minutes, the User Login WApplication timed out because there was no events keeping the session alive and hence it is destroyed.

What I did was reinitialized the session in the Main WApplication and log in the user manually into the session.
user_ = session_.find().where("oauth_id = ?").bind(loginID_);
Wt::Auth::User userTest = session_.users().findWithId(boost::lexical_cast(;
Wt::log("info")<<"Valid User!";
session_.login().login(userTest);//logins the user into the session


If you remember, i was using Wt::JSlot to perform
Wt::JSlot myJSFunc2;
std::string js;
js = "function(){'URL','someName')};";
myJSFunc2 = new Wt::JSlot(js);

A problem arising from is that a the page created is always refreshed. Since I only wanted the page to come into focus, I had to find a workaround. I played with awhile in w3schools and found out that I can actually do window.location.assign();

So this was my solution:

var myWindow ='','name'); if( myWindow.location.href == 'about:blank'){ myWindow.location.assign('URL'); }

So, if it is a blank page, it will open my URL, if not … actually it can’t do anything if it’s not a blank page. There is a security feature that prevents anything from being done to the page. I guess this solves the problem.



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.