X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fmessages.c;h=9d98dbff88ae852b57ef3db6ed9b6e6dfc712058;hb=0b2541420086a2e924ba5f192f36c137b958993c;hp=d661c9e356e674cdc1a69592179131c82b847ee6;hpb=8beca0ff3a7fad94d2e3a6134919dbb10bcb3b03;p=umurmur.git diff --git a/src/messages.c b/src/messages.c index d661c9e..9d98dbf 100644 --- a/src/messages.c +++ b/src/messages.c @@ -267,9 +267,8 @@ int Msg_messageToNetwork(message_t *msg, uint8_t *buffer) static message_t *Msg_create_nopayload(messageType_t messageType) { - message_t *msg = Memory_safeMalloc(1, sizeof(message_t)); + message_t *msg = Memory_safeCalloc(1, sizeof(message_t)); - memset(msg, 0, sizeof(message_t)); msg->refcount = 1; msg->messageType = messageType; init_list_entry(&msg->node); @@ -382,14 +381,12 @@ message_t *Msg_banList_create(int n_bans) message_t *msg = Msg_create_nopayload(BanList); int i; - msg->payload.banList = Memory_safeMalloc(1, sizeof(MumbleProto__BanList)); - memset(msg->payload.banList, 0, sizeof(MumbleProto__BanList)); + msg->payload.banList = Memory_safeCalloc(1, sizeof(MumbleProto__BanList)); mumble_proto__ban_list__init(msg->payload.banList); msg->payload.banList->n_bans = n_bans; - msg->payload.banList->bans = Memory_safeMalloc(1, sizeof(MumbleProto__BanList__BanEntry *) * n_bans); + msg->payload.banList->bans = Memory_safeMalloc(n_bans, sizeof(MumbleProto__BanList__BanEntry *)); for (i = 0; i < n_bans; i++) { - msg->payload.banList->bans[i] = Memory_safeMalloc(1, sizeof(MumbleProto__BanList__BanEntry)); - memset(msg->payload.banList->bans[i], 0, sizeof(MumbleProto__BanList__BanEntry)); + msg->payload.banList->bans[i] = Memory_safeCalloc(1, sizeof(MumbleProto__BanList__BanEntry)); mumble_proto__ban_list__ban_entry__init(msg->payload.banList->bans[i]); } return msg; @@ -455,12 +452,9 @@ void Msg_free(message_t *msg) if (msg->unpacked) mumble_proto__version__free_unpacked(msg->payload.version, NULL); else { - if (msg->payload.version->release) - free(msg->payload.version->release); - if (msg->payload.version->os) - free(msg->payload.version->os); - if (msg->payload.version->os_version) - free(msg->payload.version->os_version); + free(msg->payload.version->release); + free(msg->payload.version->os); + free(msg->payload.version->os_version); free(msg->payload.version); } break; @@ -505,14 +499,10 @@ void Msg_free(message_t *msg) if (msg->unpacked) mumble_proto__text_message__free_unpacked(msg->payload.textMessage, NULL); else { - if (msg->payload.textMessage->message) - free(msg->payload.textMessage->message); - if (msg->payload.textMessage->session) - free(msg->payload.textMessage->session); - if (msg->payload.textMessage->channel_id) - free(msg->payload.textMessage->channel_id); - if (msg->payload.textMessage->tree_id) - free(msg->payload.textMessage->tree_id); + free(msg->payload.textMessage->message); + free(msg->payload.textMessage->session); + free(msg->payload.textMessage->channel_id); + free(msg->payload.textMessage->tree_id); free(msg->payload.textMessage); } break; @@ -550,12 +540,9 @@ void Msg_free(message_t *msg) if (msg->unpacked) mumble_proto__channel_state__free_unpacked(msg->payload.channelState, NULL); else { - if (msg->payload.channelState->name) - free(msg->payload.channelState->name); - if (msg->payload.channelState->description) - free(msg->payload.channelState->description); - if (msg->payload.channelState->links) - free(msg->payload.channelState->links); + free(msg->payload.channelState->name); + free(msg->payload.channelState->description); + free(msg->payload.channelState->links); free(msg->payload.channelState); } break; @@ -598,29 +585,20 @@ void Msg_free(message_t *msg) if (msg->unpacked) mumble_proto__user_stats__free_unpacked(msg->payload.userStats, NULL); else { - if (msg->payload.userStats->from_client) - free(msg->payload.userStats->from_client); - if (msg->payload.userStats->from_server) - free(msg->payload.userStats->from_server); + free(msg->payload.userStats->from_client); + free(msg->payload.userStats->from_server); if (msg->payload.userStats->version) { - if (msg->payload.userStats->version->release) - free(msg->payload.userStats->version->release); - if (msg->payload.userStats->version->os) - free(msg->payload.userStats->version->os); - if (msg->payload.userStats->version->os_version) - free(msg->payload.userStats->version->os_version); - + free(msg->payload.userStats->version->release); + free(msg->payload.userStats->version->os); + free(msg->payload.userStats->version->os_version); free(msg->payload.userStats->version); } - if (msg->payload.userStats->celt_versions) - free(msg->payload.userStats->celt_versions); + free(msg->payload.userStats->celt_versions); if (msg->payload.userStats->certificates) { - if (msg->payload.userStats->certificates->data) - free(msg->payload.userStats->certificates->data); + free(msg->payload.userStats->certificates->data); free(msg->payload.userStats->certificates); } - if (msg->payload.userStats->address.data) - free(msg->payload.userStats->address.data); + free(msg->payload.userStats->address.data); free(msg->payload.userStats); }