[libdvbpsi-devel] src/dvbpsi.c: Use va_end() on error path of message functions.
Jean-Paul Saman
git at videolan.org
Wed Apr 16 15:53:38 CEST 2014
libdvbpsi | branch: master | Jean-Paul Saman <jpsaman at videolan.org> | Wed Apr 16 11:17:59 2014 +0200| [afca8c8e3735dec999903ed721f1523633458896] | committer: Jean-Paul Saman
src/dvbpsi.c: Use va_end() on error path of message functions.
> http://git.videolan.org/gitweb.cgi/libdvbpsi.git/?a=commit;h=afca8c8e3735dec999903ed721f1523633458896
---
src/dvbpsi.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/dvbpsi.c b/src/dvbpsi.c
index d441ee4..89d4932 100644
--- a/src/dvbpsi.c
+++ b/src/dvbpsi.c
@@ -527,9 +527,12 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char
int err = vasprintf(&msg, fmt, ap);
#else
msg = malloc(DVBPSI_MSG_SIZE);
- if (msg == NULL)
+ if (msg == NULL) {
+ va_end(ap);
return;
+ }
if (snprintf(&msg, DVBPSI_MSG_SIZE, DVBPSI_MSG_FORMAT, ap) < 0) {
+ va_end(ap);
free(msg);
return;
}
@@ -553,10 +556,13 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char
va_start(ap, fmt); \
char *tmp = NULL; \
int err = vasprintf(&tmp, fmt, ap); \
- if (err < 0) \
+ if (err < 0) { \
+ va_end(ap); \
return; \
+ } \
char *msg = NULL; \
if (asprintf(&msg, DVBPSI_MSG_FORMAT, src, tmp) < 0) { \
+ va_end(ap); \
free(tmp); \
return; \
} \
@@ -574,10 +580,14 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char
va_list ap; \
va_start(ap, fmt); \
char *msg = malloc(DVBPSI_MSG_SIZE); \
- if (msg == NULL) \
+ if (msg == NULL) { \
+ va_end(ap); \
return; \
- if (snprintf(&msg, DVBPSI_MSG_SIZE, DVBPSI_MSG_FORMAT, src) < 0) \
+ } \
+ if (snprintf(&msg, DVBPSI_MSG_SIZE, DVBPSI_MSG_FORMAT, src) < 0) { \
+ va_end(ap); \
return; \
+ } \
int err = vsnprintf(&msg, DVBPSI_MSG_SIZE, fmt, ap); \
va_end(ap); \
if (err > 0) { \
More information about the libdvbpsi-devel
mailing list