[CDRIVER-801] Reopen - Segmentation fault during driver initialization Created: 12/Aug/15  Updated: 03/May/17  Resolved: 12/Aug/15

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.1.6, 1.1.10
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jan Slesinger Assignee: Hannes Magnusson
Resolution: Duplicate Votes: 0
Labels: crash
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux czcholsint755.prg-dc.dhl.com 2.6.32-504.12.2.el6.x86_64 #1 SMP Sun Feb 1 12:14:02 EST 2015 x86_64 x86_64 x86_64 GNU/Linux

Red Hat Enterprise Linux Server release 6.3 (Santiago)

gcc (GCC) 4.4.6 20120305 (Red Hat 4.4.6-4)

MongoDB 3.0.3, WT


Issue Links:
Related
is related to CDRIVER-773 Segmentation fault during driver init... Closed

 Description   

Hello,

This simple C program

test.c

#include <mongoc.h>
#include <stdio.h>
 
mongoc_client_pool_t *client_pool;
 
void mongodb_new()
{
mongoc_client_t *client;
const char *uristr = "mongodb://127.0.0.1/";
mongoc_init ();
client = mongoc_client_new (uristr);
if (!client) {
      fprintf (stderr, "Failed to parse URI.\n");
}
}
 
void mongodb_delete()
{
        mongoc_client_pool_destroy(client_pool);
        mongoc_cleanup();
}
 
int main (int   argc, char *argv[])
{
  mongodb_new();
  //mongodb_delete();
}

compiled as:

gcc ./test.c -o test -lmongoc-1.0 -I/usr/local/include/libmongoc-1.0  -I/usr/local/include/libbson-1.0

throws segmentation fault when run under Valgrind:
valgrind --leak-check=yes ./test
See output below:

2015/07/31 17:47:26.0543: [ 6989]:    DEBUG:      cluster: Client initialized in direct mode.
==6989== Jump to the invalid address stated on the next line
==6989==    at 0xFFFFFFFFFF600800: ???
==6989==    by 0x4006E4: mongodb_new (in /appl/INSTALL/ESBArchivingLogging/aggr/src/test)
==6989==    by 0x400749: main (in /appl/INSTALL/ESBArchivingLogging/aggr/src/test)
==6989==  Address 0xffffffffff600800 is not stack'd, malloc'd or (recently) free'd
==6989==
==6989==
==6989== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==6989==  Bad permissions for mapped region at address 0xFFFFFFFFFF600800
==6989==    at 0xFFFFFFFFFF600800: ???
==6989==    by 0x4006E4: mongodb_new (in /appl/INSTALL/ESBArchivingLogging/aggr/src/test)
==6989==    by 0x400749: main (in /appl/INSTALL/ESBArchivingLogging/aggr/src/test)
==6989==
==6989== HEAP SUMMARY:
==6989==     in use at exit: 3,930 bytes in 13 blocks
==6989==   total heap usage: 39 allocs, 26 frees, 6,294 bytes allocated
==6989==
==6989== 3,930 (192 direct, 3,738 indirect) bytes in 1 blocks are definitely lost in loss record 13 of 13
==6989==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==6989==    by 0x4E59816: bson_malloc0 (in /usr/local/lib/libbson-1.0.so.0.0.0)
==6989==    by 0x4C2361D: mongoc_client_new (in /usr/local/lib/libmongoc-1.0.so.0.0.0)
==6989==    by 0x4006E4: mongodb_new (in /appl/INSTALL/ESBArchivingLogging/aggr/src/test)
==6989==    by 0x400749: main (in /appl/INSTALL/ESBArchivingLogging/aggr/src/test)
==6989==
==6989== LEAK SUMMARY:
==6989==    definitely lost: 192 bytes in 1 blocks
==6989==    indirectly lost: 3,738 bytes in 12 blocks
==6989==      possibly lost: 0 bytes in 0 blocks
==6989==    still reachable: 0 bytes in 0 blocks
==6989==         suppressed: 0 bytes in 0 blocks
==6989==
==6989== For counts of detected and suppressed errors, rerun with: -v
==6989== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 6 from 6)
Segmentation fault

Any idea what is wrong?
Thank you in advance for help.
Regards
Jan



 Comments   
Comment by Jan Slesinger [ 12/Aug/15 ]

Hello Hannes,

Sorry for late response, I was on vacation. I could not reopen this issue so I cloned it. Original issue is CDRIVER-773

Version of Valgrind used is: valgrind-3.6.0

I have also tried the same excercise in Ubuntu 14.04 with valgrind-3.10.0 with exactly the same results.

It runs with no errors without valgrind. The thing is I get memory problems in my application later which I wanted to resolve using valgrind. I have isoleted the problem step by step to the simple C program that I have attached earlier.

What platform do you use for builing so that it runs correctly for you? I will try to get there, too.

Here is my gdb session

[esb@czcholsint755 src]$ gcc ./test.c -ggdb -o test2 -lmongoc-1.0 -I/usr/local/include/libmongoc-1.0  -I/usr/local/include/libbson-1.0
[esb@czcholsint755 src]$ gdb ./test2
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-75.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /appl/INSTALL/ESBArchivingLogging/aggr/src/test2...done.
(gdb) run
Starting program: /appl/INSTALL/ESBArchivingLogging/aggr/src/test2
[Thread debugging using libthread_db enabled]
 
Program exited with code 0320.
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.149.el6_6.9.x86_64
(gdb) bt
No stack.
(gdb) strace
Segmentation fault

If I run the program with empty main() it returns
Program exited with code 0140.

Thank you
Kind regards,
Jan

Generated at Wed Feb 07 21:10:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.