Results 1 to 3 of 3

Thread: Stack smashing after thread finishes running

  1. #1
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    4

    Default Stack smashing after thread finishes running

    hi there,

    i have a little problem with my qt software. the software uses usblib to connect to a custom made hid device. normally connecting/disconnecting the device works fine with the software detecting if the device has been connected or disconnected.

    but the problem im having is the after i send data to the device with this function:

    Qt Code:
    1. void UsbCom::sendData()
    2. {
    3. mutex->lock();
    4. int r,transf;
    5. r = libusb_interrupt_transfer(devh, EP_INTR_OUT,data, 64,&transf,100);
    6. send = false;
    7. mutex->unlock();
    8. }
    To copy to clipboard, switch view to plain text mode 

    and the disconnecting the device gives me a stack smashing error. the callback function that detects if the device has been disconnected:

    Qt Code:
    1. void ep_irq_in_cb(libusb_transfer *transfer)
    2. {
    3. int *data = static_cast<int*>(transfer->user_data);
    4. if(transfer->status != LIBUSB_TRANSFER_COMPLETED)
    5. {
    6. fprintf(stderr, "uncompleted transter\n");
    7. }
    8. else
    9. {
    10. *data = 1;
    11. }
    12. if (libusb_submit_transfer(transfer) < 0)
    13. {
    14. *data = 2; //device disconnected
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    the loop function that uses a switch for *data

    Qt Code:
    1. void UsbCom::run()
    2. {
    3. int r;
    4. unsigned char temp[64];
    5. r = libusb_init(NULL); //initialize libusb
    6. send = false;
    7. if (r < 0)
    8. {
    9. emit error("Failed to initialize USB!");
    10.  
    11. }
    12. if (openDevice()) //if device handle can be opened
    13. {
    14. if (detachKernel()) //if kernel driver can be detached
    15. {
    16. if (claimInterface()) //if interface can be claimed
    17. {
    18. //true
    19. int a = 0;
    20. irq_transfer = libusb_alloc_transfer(0);
    21. libusb_fill_interrupt_transfer(irq_transfer, devh, EP_INTR_IN, irqbuf,sizeof(irqbuf), ep_irq_in_cb, &a,10);
    22. libusb_submit_transfer(irq_transfer);
    23. emit error("2");
    24. while(1)
    25. {
    26. if(send)
    27. {
    28. sendData();
    29. }
    30. if (a == 1)
    31. {
    32. for (int i = 0; i<128; i++)
    33. {
    34. temp[i] = irqbuf[i];
    35. }
    36. emit dataRecieved(temp);
    37. a = 0;
    38. }
    39. if (a == 2)
    40. {
    41. break; //device has been disconnected so stop checking for things
    42. }
    43. r = libusb_handle_events(NULL);
    44. }
    45. }
    46. }
    47. emit error("1"); //emit signal to main thread
    48. libusb_close(devh); //close device handle
    49. }
    50. } //stack smashing occurs here
    To copy to clipboard, switch view to plain text mode 

    error output:

    *** stack smashing detected ***: /home/sisco/Desktop/release/bin/Project terminated
    ======= Backtrace: =========
    /lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)[0xb6d3cda8]
    /lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x0)[0xb6d3cd60]
    /home/sisco/Desktop/release/bin/Project[0x805e640]
    [0x0]

    complete error output is in the 2 attachments

    i have tried finding the problem reading the code line by line for at least a million times but im pretty new to Qt and c++ so couldn't find anything. can anybody point me in the right direction on how to solve this problem?

    thanks,

    SIsco
    Attached Files Attached Files
    Last edited by sisco; 7th January 2010 at 09:23.

  2. #2
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Stack smashing after thread finishes running

    Qt Code:
    1. unsigned char temp[64];
    2. ...
    3. for (int i = 0; i<128; i++)
    4. {
    5. temp&[i] = irqbuf[i];
    6. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to numbat for this useful post:

    sisco (7th January 2010)

  4. #3
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    4

    Default Re: Stack smashing after thread finishes running

    much love, finnaly found it!

    temp was only 64 long while irqbuff was 128.
    this was driving me crazy, i cant believe i didnt see that =/

Similar Threads

  1. Replies: 2
    Last Post: 5th November 2009, 03:02
  2. how to terminate a thread when it is running
    By guchangyuan in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2009, 10:50
  3. running() - Thread
    By sabeesh in forum Qt Programming
    Replies: 5
    Last Post: 9th October 2007, 18:45
  4. QThread: Destroyed while thread is still running
    By Shuchi Agrawal in forum Newbie
    Replies: 8
    Last Post: 3rd April 2007, 06:27
  5. how isRunning() finds thread is running?
    By quickNitin in forum Newbie
    Replies: 1
    Last Post: 13th June 2006, 08:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.