From 2d71e692ac7d06336041eff60b2f7bcb4a601b5d Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 7 Aug 2012 14:22:27 +0200 Subject: [PATCH] nfctype2: Fix possible memory leak in nfctype2_read_meta If call to near_adapter_send() failed cookie should be freed before returning. --- plugins/nfctype2.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/nfctype2.c b/plugins/nfctype2.c index e5cf764..4a9405d 100644 --- a/plugins/nfctype2.c +++ b/plugins/nfctype2.c @@ -268,7 +268,8 @@ static int nfctype2_read_meta(uint32_t adapter_idx, uint32_t target_idx, { struct type2_cmd cmd; struct t2_cookie *cookie; - + int err; + DBG(""); cmd.cmd = CMD_READ; @@ -282,8 +283,12 @@ static int nfctype2_read_meta(uint32_t adapter_idx, uint32_t target_idx, cookie->target_idx = target_idx; cookie->cb = cb; - return near_adapter_send(adapter_idx, (uint8_t *)&cmd, CMD_READ_SIZE, + err = near_adapter_send(adapter_idx, (uint8_t *)&cmd, CMD_READ_SIZE, meta_recv, cookie); + if (err < 0) + g_free(cookie); + + return err; } static int nfctype2_read(uint32_t adapter_idx, -- 2.7.4