diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2014-03-20 14:29:42 +0100 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2014-03-21 22:29:24 +0100 |
commit | 37396e2fe5c451c466f93f852a3559da023fc98c (patch) | |
tree | 777fb15e95b988e2d89172d3f8b250d14fe0bfc7 /daemons/clvmd/clvmd.c | |
parent | 28479946249611f7f103c1caa33033a92ea0ce49 (diff) | |
download | lvm2-37396e2fe5c451c466f93f852a3559da023fc98c.tar.gz |
clvmd: update add_reply_to_list
Take mutex lock after the allocation just before
the structure is merged into reply list.
Diffstat (limited to 'daemons/clvmd/clvmd.c')
-rw-r--r-- | daemons/clvmd/clvmd.c | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c index ba3fc840e..c3268a705 100644 --- a/daemons/clvmd/clvmd.c +++ b/daemons/clvmd/clvmd.c @@ -1675,32 +1675,29 @@ static void add_reply_to_list(struct local_client *client, int status, { struct node_reply *reply; - pthread_mutex_lock(&client->bits.localsock.reply_mutex); - /* Add it to the list of replies */ - if ((reply = dm_malloc(sizeof(*reply)))) { - reply->status = status; - clops->name_from_csid(csid, reply->node); - DEBUGLOG("Reply from node %s: %d bytes\n", reply->node, len); - - if (len > 0) { - if (!(reply->replymsg = dm_malloc(len))) - reply->status = ENOMEM; - else { - memcpy(reply->replymsg, buf, len); - } - } else { - reply->replymsg = NULL; - } - /* Hook it onto the reply chain */ - reply->next = client->bits.localsock.replies; - client->bits.localsock.replies = reply; - } else { + if (!(reply = dm_zalloc(sizeof(*reply)))) { /* It's all gone horribly wrong... */ - pthread_mutex_unlock(&client->bits.localsock.reply_mutex); send_local_reply(client, ENOMEM, client->fd); return; } + + reply->status = status; + clops->name_from_csid(csid, reply->node); + DEBUGLOG("Reply from node %s: %d bytes\n", reply->node, len); + + if (len > 0) { + if (!(reply->replymsg = dm_malloc(len))) + reply->status = ENOMEM; + else + memcpy(reply->replymsg, buf, len); + } else + reply->replymsg = NULL; + + pthread_mutex_lock(&client->bits.localsock.reply_mutex); + /* Hook it onto the reply chain */ + reply->next = client->bits.localsock.replies; + client->bits.localsock.replies = reply; DEBUGLOG("Got %d replies, expecting: %d\n", client->bits.localsock.num_replies + 1, client->bits.localsock.expected_replies); |