zf8848 / libjingle

Automatically exported from code.google.com/p/libjingle
0 stars 0 forks source link

Put call example codes in a new thread, Program received signal SIGSEGV, Segmentation fault. #101

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. build libjingle-0.5.1 and successfully execute call example from shell.
2. Put call example codes into a new thread .in call_main.cc,like this:
   //int main(int argc, char **argv) {
    int veni_main(void) {
  //mask argc and argv,instead of fixed username,passwd
   }
   pthread_t thread_jingle;

  void* threadFunc(void* lpvoid)
  {
        veni_main();
        pthread_exit(&thread_jingle);
        return NULL;
  }

  int main(int argc, char **argv) 
 {
     int ret;

     ret=pthread_create(&thread_jingle,NULL,threadFunc, NULL);
     if(ret!=0)
    printf("kjfksd\n");             

     ret = pthread_join(thread_jingle, &thread_result);
     if (ret != 0) {
    perror("Thread join failed");
    exit(EXIT_FAILURE);
  }

 }

3. build ,start call

What is the expected output? What do you see instead?

[veni@veni obj]$ ls
base  call  examples  libexpat.a  libjingle.a  libsrtp.a  libxmpphelp.a  login  
p2p  relayserver  session  stunserver  third_party  xmllite  xmpp
[veni@veni obj]$ ./call 
Logging in to talk.google.com as wangsq@gmail.com
Segmentation fault  (core dumped)

why?

What version of the product are you using? On what operating system?
libjingle-0.5.1 ,Fedora13 and Android 2.1

Please provide any additional information below.

[veni@veni obj]$ gdb ./call 
GNU gdb (GDB) Fedora (7.1-18.fc13)
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 "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from 
/home/veni/mygtalk/libjingle-0.5.1/talk/build/dbg/obj/call...done.
(gdb) r
Starting program: /home/veni/mygtalk/libjingle-0.5.1/talk/build/dbg/obj/call 
[Thread debugging using libthread_db enabled]
[New Thread 0x1944b70 (LWP 4115)]
Logging in to talk.google.com as wangsq@gmail.com
[New Thread 0x5fc7b70 (LWP 4116)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x1944b70 (LWP 4115)]
0x0808027c in talk_base::MessageQueue::socketserver (this=0x0) at 
/home/veni/mygtalk/libjingle-0.5.1/talk/base/messagequeue.h:164
164   SocketServer* socketserver() { return ss_; }
Missing separate debuginfos, use: debuginfo-install alsa-lib-1.0.23-1.fc13.i686 
glibc-2.12-1.i686 libgcc-4.4.4-2.fc13.i686 libstdc++-4.4.4-2.fc13.i686
(gdb) 

Original issue reported on code.google.com by eefolks@gmail.com on 24 Nov 2010 at 12:48

GoogleCodeExporter commented 9 years ago
i have located the problem.

in the call_main.cc  file
talk_base::Thread* main_thread = talk_base::Thread::Current();
the value of main_thread is equal NULL

so,in the XmppSocket constructor
  talk_base::Thread* pth = talk_base::Thread::Current();
  talk_base::AsyncSocket* socket =
    pth->socketserver()->CreateAsyncSocket(SOCK_STREAM);
cause Segmentation fault

why the talk_base::Thread::Current() return NULL ,in a linux thread .(i hava 
encapsulated the call example codes into a linux thread)

i am a newbie for libjingle .
Anyone can help?

Best regards

Original comment by eefolks@gmail.com on 26 Nov 2010 at 9:28

GoogleCodeExporter commented 9 years ago
I have solved the problem when i hack the call_main.cc in libjingle 0.4.
but still do not how the reason.maybe i should dive into the libjingle.

Original comment by eefolks@gmail.com on 27 Nov 2010 at 4:28

GoogleCodeExporter commented 9 years ago
you can try adding
  talk_base::ThreadManager::WrapCurrentThread();

before
  talk_base::Thread* main_thread = talk_base::Thread::Current();

Original comment by ala...@gmail.com on 16 Jul 2011 at 7:25

GoogleCodeExporter commented 9 years ago
Using a talk_base::Thread, or calling WrapCurrentThread, will resolve this 
problem.

Original comment by juberti@google.com on 9 Sep 2011 at 7:39