Skip to main content
Hello, I've run into a strange issue where I'm trying to wrap the d3 C functions so I can use them from nodejs. Everything compiles fine but the _CP_logon function hangs in node but not when I run it outside of node. stracing showed that there was a segmentation fault that was causing it to hang and I'm guessing something weird might be happening with the C memory that _CP_mkstr allocates and node's memory. After running my addon in valgrind, it looks like there might be a memory bug somewhere deeper down.

I ended up being able to duplicate the issue in it's most simple form by running valgrind against the cdemo project that comes with d3. I think the root issue is that there might be a double free error somewhere in pick_init or maybe a null deref (I have basically 0 experience with C so take this all with a heaping of salt).

I built cdemo using gcc 7.3 and then ran it valgrind and I see the following error which is the same error that I get through node.

[root@d3linux cdemo]# valgrind ./cdemo bp color
==48003== Memcheck, a memory error detector
==48003== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==48003== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==48003== Command: ./cdemo bp color
==48003==
==48003== Warning: client syscall shmat tried to modify addresses 0x40000000-0xf00a4fff
 WARNING: Buffer attachment failed. Error 22
==48003== Invalid read of size 8
==48003==    at 0x41E5B4: pick_init_bs_attach (in /home/nivethan/bp/cdemo/cdemo)
==48003==    by 0x41A72B: pick_init (in /home/nivethan/bp/cdemo/cdemo)
==48003==    by 0x47F768: _CP_logon (in /home/nivethan/bp/cdemo/cdemo)
==48003==    by 0x406109: main (in /home/nivethan/bp/cdemo/cdemo)
==48003==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==48003==
==48003==
==48003== Process terminating with default action of signal 11 (SIGSEGV)
==48003==  Access not within mapped region at address 0x0
==48003==    at 0x41E5B4: pick_init_bs_attach (in /home/nivethan/bp/cdemo/cdemo)
==48003==    by 0x41A72B: pick_init (in /home/nivethan/bp/cdemo/cdemo)
==48003==    by 0x47F768: _CP_logon (in /home/nivethan/bp/cdemo/cdemo)
==48003==    by 0x406109: main (in /home/nivethan/bp/cdemo/cdemo)
==48003==  If you believe this happened as a result of a stack
==48003==  overflow in your program's main thread (unlikely but
==48003==  possible), you can try to increase the size of the
==48003==  main thread stack using the --main-stacksize= flag.
==48003==  The main thread stack size used in this run was 8388608.
==48003==
==48003== HEAP SUMMARY:
==48003==     in use at exit: 170 bytes in 6 blocks
==48003==   total heap usage: 72 allocs, 66 frees, 14,471 bytes allocated
==48003==
==48003== LEAK SUMMARY:
==48003==    definitely lost: 0 bytes in 0 blocks
==48003==    indirectly lost: 0 bytes in 0 blocks
==48003==      possibly lost: 0 bytes in 0 blocks
==48003==    still reachable: 170 bytes in 6 blocks
==48003==         suppressed: 0 bytes in 0 blocks
==48003== Rerun with --leak-check=full to see details of leaked memory
==48003==
==48003== For counts of detected and suppressed errors, rerun with: -v
==48003== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
   Segmentation fault
[root@d3linux cdemo]#

If anyone has any ideas or tips I'd be happy to hear them. It could be that because the issue is deeper down, this makes more sense as a support ticket but I saw someone asking about __CP_logon on the home page so someone might have some ideas. Thanks!

------------------------------
Nivethan Thiyagarajah
Programmer
Asynchron Systems Inc
Toronto ON CA
------------------------------
Hello, I've run into a strange issue where I'm trying to wrap the d3 C functions so I can use them from nodejs. Everything compiles fine but the _CP_logon function hangs in node but not when I run it outside of node. stracing showed that there was a segmentation fault that was causing it to hang and I'm guessing something weird might be happening with the C memory that _CP_mkstr allocates and node's memory. After running my addon in valgrind, it looks like there might be a memory bug somewhere deeper down.

I ended up being able to duplicate the issue in it's most simple form by running valgrind against the cdemo project that comes with d3. I think the root issue is that there might be a double free error somewhere in pick_init or maybe a null deref (I have basically 0 experience with C so take this all with a heaping of salt).

I built cdemo using gcc 7.3 and then ran it valgrind and I see the following error which is the same error that I get through node.

[root@d3linux cdemo]# valgrind ./cdemo bp color
==48003== Memcheck, a memory error detector
==48003== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==48003== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==48003== Command: ./cdemo bp color
==48003==
==48003== Warning: client syscall shmat tried to modify addresses 0x40000000-0xf00a4fff
 WARNING: Buffer attachment failed. Error 22
==48003== Invalid read of size 8
==48003==    at 0x41E5B4: pick_init_bs_attach (in /home/nivethan/bp/cdemo/cdemo)
==48003==    by 0x41A72B: pick_init (in /home/nivethan/bp/cdemo/cdemo)
==48003==    by 0x47F768: _CP_logon (in /home/nivethan/bp/cdemo/cdemo)
==48003==    by 0x406109: main (in /home/nivethan/bp/cdemo/cdemo)
==48003==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==48003==
==48003==
==48003== Process terminating with default action of signal 11 (SIGSEGV)
==48003==  Access not within mapped region at address 0x0
==48003==    at 0x41E5B4: pick_init_bs_attach (in /home/nivethan/bp/cdemo/cdemo)
==48003==    by 0x41A72B: pick_init (in /home/nivethan/bp/cdemo/cdemo)
==48003==    by 0x47F768: _CP_logon (in /home/nivethan/bp/cdemo/cdemo)
==48003==    by 0x406109: main (in /home/nivethan/bp/cdemo/cdemo)
==48003==  If you believe this happened as a result of a stack
==48003==  overflow in your program's main thread (unlikely but
==48003==  possible), you can try to increase the size of the
==48003==  main thread stack using the --main-stacksize= flag.
==48003==  The main thread stack size used in this run was 8388608.
==48003==
==48003== HEAP SUMMARY:
==48003==     in use at exit: 170 bytes in 6 blocks
==48003==   total heap usage: 72 allocs, 66 frees, 14,471 bytes allocated
==48003==
==48003== LEAK SUMMARY:
==48003==    definitely lost: 0 bytes in 0 blocks
==48003==    indirectly lost: 0 bytes in 0 blocks
==48003==      possibly lost: 0 bytes in 0 blocks
==48003==    still reachable: 170 bytes in 6 blocks
==48003==         suppressed: 0 bytes in 0 blocks
==48003== Rerun with --leak-check=full to see details of leaked memory
==48003==
==48003== For counts of detected and suppressed errors, rerun with: -v
==48003== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
   Segmentation fault
[root@d3linux cdemo]#

If anyone has any ideas or tips I'd be happy to hear them. It could be that because the issue is deeper down, this makes more sense as a support ticket but I saw someone asking about __CP_logon on the home page so someone might have some ideas. Thanks!

------------------------------
Nivethan Thiyagarajah
Programmer
Asynchron Systems Inc
Toronto ON CA
------------------------------
I think a support ticket is in order for this one, and we'll need to get Engineering involved. When you log the ticket, please include a WHICH CAD from TCL so we have the system ID, the platform, the D3 version, and the exact patch level. Thanks.

------------------------------
Brian S. Cram
Principal Technical Support Engineer
Rocket Software
------------------------------