--- uim/uim-helper-client.c 2006-12-22 05:32:42.000000000 +0100 +++ uim/uim-helper-client.c 2007-07-03 20:48:12.000000000 +0200 @@ -72,14 +72,15 @@ int uim_helper_init_client_fd(void (*disconnect_cb)(void)) { - int fd; struct sockaddr_un server; char *path = uim_helper_get_pathname(); + FILE *serv_r = NULL, *serv_w = NULL; + int fd = -1; uim_fd = -1; if (!path) - return -1; + goto error; bzero(&server, sizeof(server)); server.sun_family = PF_UNIX; @@ -90,7 +91,7 @@ fd = socket(PF_UNIX, SOCK_STREAM, 0); if (fd < 0) { perror("fail to create socket"); - return -1; + goto error; } #ifdef LOCAL_CREDS /* for NetBSD */ @@ -104,34 +105,41 @@ if (connect(fd, (struct sockaddr *)&server,sizeof(server)) == -1) { int serv_pid = 0; - FILE *serv_r = NULL, *serv_w = NULL; char buf[128]; serv_pid = uim_ipc_open_command(serv_pid, &serv_r, &serv_w, get_server_command()); - if (serv_pid == 0) { - return -1; - } + if (serv_pid == 0) + goto error; while (fgets (buf, sizeof(buf), serv_r ) != NULL ) { if (strcmp( buf, "\n" ) == 0) break; } - if (connect(fd, (struct sockaddr *)&server,sizeof(server)) == -1) { - return -1; - } + if (connect(fd, (struct sockaddr *)&server,sizeof(server)) == -1) + goto error; } - if (uim_helper_check_connection_fd(fd)) { - close(fd); - return -1; - } + if (uim_helper_check_connection_fd(fd)) + goto error; uim_read_buf = strdup(""); uim_disconnect_cb = disconnect_cb; uim_fd = fd; return fd; + +error: + if (fd != -1) { + close(fd); + } + if (serv_r) { + fclose(serv_r); + } + if (serv_w) { + fclose(serv_w); + } + return -1; } void