Coder Social home page Coder Social logo

example.c ends in a segfault about libuvc HOT 2 OPEN

libuvc avatar libuvc commented on August 22, 2024
example.c ends in a segfault

from libuvc.

Comments (2)

coreylowman avatar coreylowman commented on August 22, 2024

I am currently running it on a beaglebone black, and sometimes it runs fine, but sometimes it does segfault. I ran gdb on it and it seems like its crashing in a call libusb. It crashes in uvc_stop_streaming call.

from libuvc.

ovchinnikov-v-a avatar ovchinnikov-v-a commented on August 22, 2024

It seems I've had the same trouble - my app using libuvc crashes when trying to close device with uvc_close() after starting a stream with uvc_stream_start().

The actual problem was in function called uvc_stream_stop - there is erroneous usage of libusb_cancel_transfer return value:

int res = libusb_cancel_transfer(strmh->transfers[i]); if(res < 0) { free(strmh->transfers[i]->buffer); libusb_free_transfer(strmh->transfers[i]); strmh->transfers[i] = NULL; }

It is not valid to free transfer immediately after libusb_cancel_transfer returned negative result cause this transfer may still be used in uvc_iso_callback function.

So I commented out transfer freeing code in uvc_stream_stop and add transfer deletion to uvc_iso_callback for LIBUSB_TRANSFER_COMPLETED, LIBUSB_TRANSFER_TIMED_OUT, LIBUSB_TRANSFER_STALL and LIBUSB_TRANSFER_OVERFLOW cases.
Of course transfer deletion in uvc_iso_callback for these cases should happen only when strmh->running == 0.

I'm not sure if this quick and dirty solution is the best one, but it works for me - no more crashes when calling uvc_close(). My current version of stream.c is attached.
stream.zip

from libuvc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.