ustd: improve error handling
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Thu, 25 Feb 2010 02:06:47 +0000 (21:06 -0500)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Thu, 25 Feb 2010 23:01:25 +0000 (18:01 -0500)
ustd/ustd.c

index 7882e34544278f4cd68a08303670e8b8d35d75ea..d2a9712a20c1ca78cbe99cc6be7337be9c602e31 100644 (file)
@@ -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)
This page took 0.025203 seconds and 4 git commands to generate.