Quellcode durchsuchen

calipso: fix resource leak on calipso_genopt failure

Currently, if calipso_genopt fails then the error exit path
does not free the ipv6_opt_hdr new causing a memory leak. Fix
this by kfree'ing new on the error exit path.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Colin Ian King vor 9 Jahren
Ursprung
Commit
b4c0e0c61f
1 geänderte Dateien mit 3 neuen und 1 gelöschten Zeilen
  1. 3 1
      net/ipv6/calipso.c

+ 3 - 1
net/ipv6/calipso.c

@@ -952,8 +952,10 @@ calipso_opt_insert(struct ipv6_opt_hdr *hop,
 		memcpy(new, hop, start);
 		memcpy(new, hop, start);
 	ret_val = calipso_genopt((unsigned char *)new, start, buf_len, doi_def,
 	ret_val = calipso_genopt((unsigned char *)new, start, buf_len, doi_def,
 				 secattr);
 				 secattr);
-	if (ret_val < 0)
+	if (ret_val < 0) {
+		kfree(new);
 		return ERR_PTR(ret_val);
 		return ERR_PTR(ret_val);
+	}
 
 
 	buf_len = start + ret_val;
 	buf_len = start + ret_val;
 	/* At this point buf_len aligns to 4n, so (buf_len & 4) pads to 8n */
 	/* At this point buf_len aligns to 4n, so (buf_len & 4) pads to 8n */