execve "Bad address" error

As the title suggests, I'm getting a "Bad Address" error when calling execve(). Whenever I found someone else having the same problem, they were just omitting the NULLs at the end of the arrays, but I'm doing that here and I'm still getting the error. Anybody know what could be causing it?

switch(fork()) {
    case 0: //child
        (void) close(msock);
        char *argv[] = {"./echo", (char *)ssock, NULL};
        char *envp[] = {NULL};
        int result = execve(argv[0], argv, envp);
        if (result < 0) {
    case -1: //error
    default: //parent
        (void) close(ssock);


Based on your code, ssock is an integer, a file descriptor, since you are passing it to close() in the default case (parent).

However, you are also passing that integer as a character pointer to execve in the argument list (in the child case). It is unlikely that such an integer will map to a valid memory address, hence your error. In fact, even if it did map to a valid address, the program would most likely crash anyway since that address would probably not contain a valid string; at the very least, you would get unexpected results.

Need Your Help

Vertically align content inside Superslides

jquery html css vertical-alignment

Im trying to use both Superslides (https://github.com/nicinabox/superslides/) and Boostrap 3 on a site.

Rotating the uiview without IB

iphone uiview uiinterfaceorientation

In my app all my controls are created in code. I have not used IB for controls. now i want to rotate the view to landscape mode. I know I have to use the shouldAutorotate method for this purpose.