rpc: Avoid accessing unitted memory in send_init() in error cases

There's an error path that looks like this:
  send_init()
  -> get_socket()
     -> some error before *sd is assigned

...then we'll end up at send_init()'s "err_exit" call and try to
close(sd) without it ever having been initted.

Let's init sd to -1 and only close it when it's been initted.  Note
that the docs for open() and socket() show that -1 is an error
condition so it should be safe to do this.

This error was found by code inspection.  No known problems are solved
by this patch, but it does clean up error handling.

BUG=None
TEST=Compile

Change-Id: I8e69f1c2820e39cbd21b26fd0ffe8939ddb6f21f
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/923573
Reviewed-by: Andrey Pronin <apronin@chromium.org>
1 file changed