From 54b7f9ca44b9e4c046cbb05bcea68cd369f389af Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Mon, 21 Apr 2014 19:51:39 +0100 Subject: [PATCH] cwc: fix potential leak spotted by EricV, and also bad var init --- src/descrambler/cwc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/descrambler/cwc.c b/src/descrambler/cwc.c index e6a58255..72ef301f 100755 --- a/src/descrambler/cwc.c +++ b/src/descrambler/cwc.c @@ -463,10 +463,14 @@ cwc_send_msg(cwc_t *cwc, const uint8_t *msg, size_t len, int sid, int enq, uint1 { cwc_message_t *cm = malloc(sizeof(cwc_message_t)); uint8_t *buf = cm->cm_data; + int seq; - if (len < 3 || len + 12 > CWS_NETMSGSIZE) return -1; + if (len < 3 || len + 12 > CWS_NETMSGSIZE) { + free(cm); + return -1; + } - int seq = atomic_add(&cwc->cwc_seq, 1); + seq = atomic_add(&cwc->cwc_seq, 1); buf[0] = buf[1] = 0; buf[2] = (seq >> 8) & 0xff;