diff --git a/libfreerdp/core/mcs.c b/libfreerdp/core/mcs.c index 31620b8c8..8202d40b2 100644 --- a/libfreerdp/core/mcs.c +++ b/libfreerdp/core/mcs.c @@ -1056,26 +1056,29 @@ rdpMcs* mcs_new(rdpTransport* transport) { rdpMcs* mcs; - mcs = (rdpMcs*) malloc(sizeof(rdpMcs)); + mcs = (rdpMcs *)calloc(1, sizeof(rdpMcs)); + if (!mcs) + return NULL; - if (mcs) - { - ZeroMemory(mcs, sizeof(rdpMcs)); + mcs->transport = transport; + mcs->settings = transport->settings; - mcs->transport = transport; - mcs->settings = transport->settings; + mcs_init_domain_parameters(&mcs->targetParameters, 34, 2, 0, 0xFFFF); + mcs_init_domain_parameters(&mcs->minimumParameters, 1, 1, 1, 0x420); + mcs_init_domain_parameters(&mcs->maximumParameters, 0xFFFF, 0xFC17, 0xFFFF, 0xFFFF); + mcs_init_domain_parameters(&mcs->domainParameters, 0, 0, 0, 0xFFFF); - mcs_init_domain_parameters(&mcs->targetParameters, 34, 2, 0, 0xFFFF); - mcs_init_domain_parameters(&mcs->minimumParameters, 1, 1, 1, 0x420); - mcs_init_domain_parameters(&mcs->maximumParameters, 0xFFFF, 0xFC17, 0xFFFF, 0xFFFF); - mcs_init_domain_parameters(&mcs->domainParameters, 0, 0, 0, 0xFFFF); - - mcs->channelCount = 0; - mcs->channelMaxCount = CHANNEL_MAX_COUNT; - mcs->channels = (rdpMcsChannel*) calloc(mcs->channelMaxCount, sizeof(rdpMcsChannel)); - } + mcs->channelCount = 0; + mcs->channelMaxCount = CHANNEL_MAX_COUNT; + mcs->channels = (rdpMcsChannel *)calloc(mcs->channelMaxCount, sizeof(rdpMcsChannel)); + if (!mcs->channels) + goto out_free; return mcs; + +out_free: + free(mcs); + return NULL; } /**