/contrib/famzah

Enthusiasm never stops


1 Comment

Firefox crashes with “terminate called after throwing an instance of ‘std::bad_alloc'”

If you are here, you probably are as desperate as I was. Though your system has plenty of memory, Firefox keeps crashing with the following error message:

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted

You can see the above error either by starting “firefox” in your console terminal manually, or by reviewing the file “~/.xsession-errors”, if you are running KDE.

I ran Firefox several times in debug mode via “gdb” and every time the debug output lead me to the wrong direction. Here is a sample full backtrace output:

[New Thread 0xadbfeb70 (LWP 3763)]
[Thread 0xadbfeb70 (LWP 3763) exited]
[New Thread 0xadbfeb70 (LWP 3764)]
[Thread 0xadbfeb70 (LWP 3764) exited]
[New Thread 0xadbfeb70 (LWP 3765)]
[New Thread 0xae3ffb70 (LWP 3766)]
[Thread 0xadbfeb70 (LWP 3765) exited]
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Program received signal SIGABRT, Aborted.
0x00227422 in ?? ()
(gdb) bt full
#0  0x00227422 in ?? ()
No symbol table info available.
#1  0x002524d1 in *__GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
        resultvar = <value optimized out>
        pid = 3575796
        selftid = 3708
#2  0x00255932 in *__GI_abort () at abort.c:92
        act = {__sigaction_handler = {sa_handler = 0x7a3ff4, sa_sigaction = 0x7a3ff4}, sa_mask = {__val = {3221183748, 3086869600, 3221183704, 7933961,
              3221183688, 1154680, 3221183676, 8013772, 0, 3086866344, 5, 0, 1, 3221183640, 0, 3221183716, 1356543, 3577255, 3221183636, 3035204, 1,
              3086869160, 0, 3221183748, 3221183676, 3221183688, 0, 4294967295, 1359583, 3086869160, 3221183680, 4294967295}}, sa_flags = 8011764,
          sa_restorer = 0x14b2ff}
        sigs = {__val = {32, 0 <repeats 31 times>}}
#3  0x001cc4df in __gnu_cxx::__verbose_terminate_handler () at ../../../../src/libstdc++-v3/libsupc++/vterminate.cc:93
        terminating = true
        t = <value optimized out>
#4  0x001ca415 in __cxxabiv1::__terminate (handler=0x1cc390 <__gnu_cxx::__verbose_terminate_handler()>)
    at ../../../../src/libstdc++-v3/libsupc++/eh_terminate.cc:38
No locals.
#5  0x001ca452 in std::terminate () at ../../../../src/libstdc++-v3/libsupc++/eh_terminate.cc:48
No locals.
#6  0x001ca591 in __cxa_throw (obj=0xad2f9700, tinfo=0x1f97fc, dest=0x1caaf0 <~bad_alloc>) at ../../../../src/libstdc++-v3/libsupc++/eh_throw.cc:83
        header = <value optimized out>
#7  0x001cac0f in operator new (sz=2) at ../../../../src/libstdc++-v3/libsupc++/new_op.cc:58
        handler = <value optimized out>
        p = <value optimized out>
#8  0x001caced in operator new[] (sz=2) at ../../../../src/libstdc++-v3/libsupc++/new_opv.cc:32
No locals.
#9  0x012ead5c in gfxSkipChars::TakeFrom (this=0xbfff5f1c, aSkipCharsBuilder=0xbfff6f60) at ../../dist/include/thebes/gfxSkipChars.h:152
No locals.
#10 0x012e48fe in BuildTextRunsScanner::BuildTextRunForFrames (this=0xbfff8320, aTextBuffer=0xbfff7280) at nsTextFrameThebes.cpp:1713
        anySmallcapsStyle = 0
        textBreakPoints = {<nsTArray<int>> = {<nsTArray_base> = {static sEmptyHdr = {mLength = 0, mCapacity = 0, mIsAutoArray = 0},
              mHdr = 0xbfff7150}, <No data fields>},
          mAutoBuf = "\001\000\000\000\062\000\000\200\000\000\000\000\220z\377\277\354x\377\277\065\000\000\000\066\000\000\000\000\000\000\000\b\000\000\000\260q\377\277\254q\377\277\220q\377\277\000\202\066\260\030V\241\265\b@q\267\066\000\000\000\240\321\377\263\270\321\377\263\000\000\000\000\b\000\000\000\001\000\000\000\000\000\000\000\b\000\000\000\b\000\000\000\000\000\000\000\304i\005\255\b\000\000\000$\301 \255\364\017\274\001\240\321\377\263\b\000\000\000\254y\377\277\201E\225\001\354x\377\277\240\321\377\263\000\000\000\000\036\352\216\001\000\000\000\000\200g/\255\220z\377\277xr\377\277\256\371\247\001\000\000\000\000\220z\377\277(;\260\001\000\000\000\000\354x\377\277\254r\377\277\364\017\274\001tr\377\277\002\000\000\000<r\377\277"}
        currentTransformedTextOffset = 1
        finalUserData = 0xad2037cc
        userDataToDestroy = 0x0
        nextBreakIndex = 2904569804
        firstFrame = 0xad2037cc
        builder = {mBuffer = {<nsTArray<unsigned char>> = {<nsTArray_base> = {static sEmptyHdr = {mLength = 0, mCapacity = 0, mIsAutoArray = 0},
                mHdr = 0xbfff6f64}, <No data fields>},
            mAutoBuf = "\002\000\000\000\000\001\000\200\001\001\377\277\223\200\223\001\027m\271\000#\000\000\000\031\201\271\000\364\017\274\001<\000\000\000\000\000\000\000\274p\377\277\347\063\225\001\027m\271\000\324\302\355\267\031\201\271\000\256^\005\b@\300\355\267\240\246z\267\004\000\000\000\364\257\005\b\000@\006\255\000\000\000\255\fp\377\277\064u\005\b@\300\355\267\000\000\002\000\320o\377\277\000\000\000\000\062\000\000\200\000\000\000\000[]\005\b\225\351\216\001\240D\006\255\374\301\355\267 \000\000\000\217\350\216\001$p\377\277\002\000\000\000\274p\377\277\225\351\216\001\f\203\377\277\370\202\377\277,p\377\277\000\000\000\000\f\203\377\277\370\202\377\277lp\377\277\000\000\000\000\370\202\377\277\004\000\000\000\002\000\000\000\364\017\274\001,\203\377\277\000\000\000\000lp\377\277_\256.\001,\203\377\277\000\000\000\000\000\000\000\000\225\351\216\001\004", '\000' <repeats 11 times>"\217, \350\216\001\240\201\37---Type <return> to continue, or q <return> to quit---

After much try-and-error attempts, and also thoughts if my laptop’s memory wasn’t faulty or if the shared libraries on my disk weren’t somehow corrupted, I was finally able to track down the cause of this abnormal behavior:

BUG: The Security Device which the Siemens HiPath SIcurity Card API provided. You can read here why I use it.

The problem started somewhere around Firefox version 3.5.5 and later. If the security device dongle/card is not plugged in your computer, Firefox crashes at random pages.

The resolution
Create a second Firefox profile and install the Security Device only there, leaving the default Firefox profile with no Security Device capabilities. Thus if you want to use your online banking, you would need to close Firefox and then start it using the second profile. It’s not that bad, if you are a personal user like me who performs bank transactions relatively rarely.

The MozillaZine Knowledge Base has an excellent article about Firefox Profile Manager.


9 Comments

Infonotary E-Signature with Cardman 6121 on Kubuntu Karmic and Lucid

There are three systems involved in using an Infonotary e-signature with a reader in Firefox 3.5/3.6 on Linux 32-bit:

Installation instructions for Kubuntu Karmic and Lucid follow:

  1. Execute the following in a terminal console:
    sudo apt-get install pcscd pcsc-omnikey
    sudo tar -C / -zxf HiPath_SIcurity_Card_API_V3_1_010_Linux.tar.gz
    sudo ln -s /lib/libpcsclite.so.1 /lib/libpcsclite.so.0
    
  2. Review the “Security device settings in Firefox 3.5/3.6” paragraph below and set up “/usr/local/lib/libsiecap11.so” in Firefox
  3. Install the Infonotary root certificate chain by following the instructions on the Infonotary wiki page. Review the “Инсталиране на удостоверителната верига на Инфонотари” section there. Make sure that you edit the CA certificate trust settings exactly as described.

Update: Since I upgraded to Lucid, when I plug in my Cardman reader, I need to restart “pcscd” and Firefox before I can use it. The command for restarting “pcscd” is “sudo /etc/init.d/pcscd restart”.


Some more detailed explanation about the above commands and programs follows. If you are in a hurry, you can safely skip them. I’m using a 32-bit installation of Kubuntu.

Drivers for the reader: Prior to Karmic 9.10 I used the “opensc” package, not the Siemens HiPath Sicurity API library. The “opensc” package no longer works for me. Make sure that the following packages are not installed on your system, the Siemens API library provides their functionality:

sudo apt-get --purge remove opensc libopensc2 libopenct1 openct libccid

Note that the Siemens API library has some dependency problems on newer systems. It is linked against “/lib/libpcsclite.so.0”, but the package “libpcsclite1” now ships “/lib/libpcsclite.so.1”. They seem fully compatible though (or are the same library?). Therefore, a symlink “/lib/libpcsclite.so.0 -> /lib/libpcsclite.so.1” must be made. You can check if your Siemens library installation works well by issuing the command “ldd /usr/local/lib/libsiecap11.so”. If you see something like the following:

libpcsclite.so.0 => not found

…then there is a problem. You have to re-check if you made the symlink as advised.
If you see something like the following:

libpcsclite.so.0 => /lib/libpcsclite.so.0 (0x00466000)

…then you are OK.

Middleware software: I’ve always used “pcscd”. On Karmic I tried “openct” too, but it didn’t work for me.

Security device settings in Firefox 3.5/3.6: Edit->Preferences->Advanced->Encryption->Security Devices->Load->Module filename: /usr/local/lib/libsiecap11.so

There are some instructions on the Infonotary Wiki page too, but I’m not positive if they are up-to-date and suitable for Kubuntu Karmic or Lucid.


Just a side note: While I was using the “opensc” drivers, I found out that if you choose “/usr/lib/onepin-opensc-pkcs11.so” for “Module filename” in Firefox, then you won’t be asked twice for your PIN code (actually the second request was for something like “Secondary authentication” PIN). Prior to this, I used “/usr/lib/libopensc-pkcs11.so” and it worked well too – I typed nothing for Secondary authentication, but it was annoying.


Download disclaimer about my copy of the “HiPath SIcurity Card API V3.1 PKCS#11 for Linux”: I uploaded the copy of this archive file as I got it from my card reader vendor. I give no guarantee for the integrity of this copy and I cannot be held liable for any security or other damage, whatsoever. You have been warned.