EXC_BAD_ACCESS with libssh2?

Discussion in 'iOS Programming' started by PXL Creations, Apr 19, 2012.

  1. macrumors member

    Nov 28, 2009
    I was finally able to compile libssh2 (thanks to a very helpful forrst'r), but now I keep seeing the `EXC_BAD_ACCESS` error.

    This is the basic background as to how libssh2 works (at least the GUI) is this...

    1. Enter command
    2. Enter host IP
    3. Enter username/pass
    4. Press the button to send the SSH command

    Now, simple commands like `echo Hello World` work fine, but the whole idea of this as a project was to be able to restart my mac remotely. Originally, using the command `shutdown -r` caused nothing to happen on the remote machine, and crashed the app. I then had the idea that I could simple open an applescript app that restarts the mac, by using the `open /path/to/restart.app` command, which works fine. The machine restarts, sweet.

    EXCEPT, the app crashes with the following error:

    Thread 1: EXC_BAD_ACCESS (code=1, address=_____)
    I'm really new to objective-c, and I have no idea how to go about fixing this. Looking it up on google, I've found that it's caused by:

    1. Memory issue
    2. Message being sent to an object that's already been released (I'm not sure what this means...)

    So, I'm guessing that once the command is sent via SSH, it disconnects and then tires to show the result but the object's already gone.

    I'd post the source code for this, but it's a lot of different files, so I'll post the github link:


    I have not modified any of the code, so if anyone has the desire to replicate my problem, the code I'm using is the same as the one from there.

    EDIT: From another forum, "... having said that you can see that libssh2_channel_open() is dereferencing a NULL pointer so you're likely passing one of the parameters as NULL. Stick a breakpoint on your call to libssh2_channel_open_ex() and check the parameters as they go in; alternatively add asserts before the call to ensure things are as you expect (a better longterm solution)." How do I follow these instructions?
  2. chown33, Apr 19, 2012
    Last edited: Apr 19, 2012

    macrumors 604

    Aug 9, 2009
    The issue that needs to be addressed is learning the tools.

    Step 1: Use a project that works.
    Seriously, learning to use breakpoints and the debugger will be much easier on a program that already works. Since the goal is learning the tools, not debugging a broken program, using a working program takes one problem out of the mix.

    Step 2: Learn to use breakpoints.
    Start by entering the search term breakpoint in Xcode's builtin documentation. Not the iOS reference docs, the builtin Help documentation for Xcode itself. Learning breakpoints also involves learning how to examine variables and interpret those values. And once a breakpoint is hit, stepping thru code a line at a time is an essential skill.

    Step 3: Read online resources.
    Found by googling xcode breakpoint site:developer.apple.com
    That last site: search term limits the results to that specific site. It's basically how to get site-specific search results without going to the site and doing a search there.
  3. macrumors newbie

    Apr 19, 2012
    Have you tried enabling Zombie Objects (NSZombieEnabled)? Usually this will help you identify where you're accessing memory that's been deallocated.
  4. thread starter macrumors member

    Nov 28, 2009
    Thanks for the reply,

    1.) I would work on a different project, but I'd like to learn how to debug a semi-working one first.

    2.) I'll take a look at the docs and google how to use breakpoints better.

    3.) Yes, I normally would search google but I find that when you don't completely understand the language, it's better to hear it from people who are working specifically on what you're working on. And yes, I've searched google like that many a times...

    What's the best way to do this? I tried going though the docs, but I couldn't find anything to guide me on how to set it up. Google's the next step I guess...


Share This Page