From: Pierre-Marc Fournier Date: Thu, 25 Feb 2010 02:06:47 +0000 (-0500) Subject: ustd: improve error handling X-Git-Tag: v0.3~27 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=0ed54020dd215419ddb85dc059d983cff25e8729;p=ust.git ustd: improve error handling --- diff --git a/ustd/ustd.c b/ustd/ustd.c index 7882e34..d2a9712 100644 --- a/ustd/ustd.c +++ b/ustd/ustd.c @@ -260,6 +260,9 @@ struct buffer_info *connect_buffer(pid_t pid, const char *bufname) ERR("problem in ustcomm_send_request(get_pidunique)"); return NULL; } + if(result == 0) { + goto error; + } result = sscanf(received_msg, "%lld", &buf->pidunique); if(result != 1) { @@ -277,6 +280,9 @@ struct buffer_info *connect_buffer(pid_t pid, const char *bufname) ERR("problem in ustcomm_send_request(get_shmid)"); return NULL; } + if(result == 0) { + goto error; + } result = sscanf(received_msg, "%d %d", &buf->shmid, &buf->bufstruct_shmid); if(result != 2) { @@ -294,6 +300,9 @@ struct buffer_info *connect_buffer(pid_t pid, const char *bufname) ERR("problem in ustcomm_send_request(g_n_subbufs)"); return NULL; } + if(result == 0) { + goto error; + } result = sscanf(received_msg, "%d", &buf->n_subbufs); if(result != 1) { @@ -305,8 +314,15 @@ struct buffer_info *connect_buffer(pid_t pid, const char *bufname) /* get subbuf size */ asprintf(&send_msg, "get_subbuf_size %s", buf->name); - ustcomm_send_request(&buf->conn, send_msg, &received_msg); + result = ustcomm_send_request(&buf->conn, send_msg, &received_msg); free(send_msg); + if(result == -1) { + ERR("problem in ustcomm_send_request(get_subbuf_size)"); + return NULL; + } + if(result == 0) { + goto error; + } result = sscanf(received_msg, "%d", &buf->subbuf_size); if(result != 1) { @@ -378,6 +394,10 @@ struct buffer_info *connect_buffer(pid_t pid, const char *bufname) pthread_mutex_unlock(&active_buffers_mutex); return buf; + +error: + free(buf); + return NULL; } int write_current_subbuffer(struct buffer_info *buf)