[PATCH 2/4] xfrm: fix memleak in another error path of build_xfrm_sa_message

Peter Wu peter at lekensteyn.nl
Mon Aug 8 02:58:51 PDT 2016


Signed-off-by: Peter Wu <peter at lekensteyn.nl>
---
 lib/xfrm/sa.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/xfrm/sa.c b/lib/xfrm/sa.c
index 1c0888b..8bfaabc 100644
--- a/lib/xfrm/sa.c
+++ b/lib/xfrm/sa.c
@@ -1175,7 +1175,10 @@ static int build_xfrm_sa_message(struct xfrmnl_sa *tmpl, int cmd, int flags, str
 			strncpy(auth->alg_name, tmpl->auth->alg_name, sizeof(auth->alg_name));
 			auth->alg_key_len = tmpl->auth->alg_key_len;
 			memcpy(auth->alg_key, tmpl->auth->alg_key, (tmpl->auth->alg_key_len + 7) / 8);
-			NLA_PUT(msg, XFRMA_ALG_AUTH, len, auth);
+			if (nla_put(msg, XFRMA_ALG_AUTH, len, auth) < 0) {
+				free(auth);
+				goto nla_put_failure;
+			}
 			free(auth);
 		}
 	}
-- 
2.9.2




More information about the libnl mailing list