From: Phil Sutter Date: Fri, 12 Aug 2016 12:39:50 +0000 (+0200) Subject: utils: Don't return directly from SNPRINTF_BUFFER_SIZE X-Git-Tag: libnftnl-1.0.7~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9afae310b019aa497afb94833afc9a936bc38a1f;p=thirdparty%2Flibnftnl.git utils: Don't return directly from SNPRINTF_BUFFER_SIZE Apart from being a bad idea in general, the return statement contained in that macro in some cases leads to returning from functions without properly cleaning up, thereby causing memory leaks. Instead, just sanitize the value in 'ret' to not harm further calls of snprintf() (as 'len' will eventually just become zero). Cc: Arturo Borrero Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- diff --git a/include/utils.h b/include/utils.h index 21694b6a..924df324 100644 --- a/include/utils.h +++ b/include/utils.h @@ -54,7 +54,7 @@ void __nftnl_assert_attr_exists(uint16_t attr, uint16_t attr_max, #define SNPRINTF_BUFFER_SIZE(ret, size, len, offset) \ if (ret < 0) \ - return ret; \ + ret = 0; \ offset += ret; \ if (ret > len) \ ret = len; \