Skip to content

Commit

Permalink
libkvs/watch: match va_start/va_end on error
Browse files Browse the repository at this point in the history
Fix cppcheck error:

[src/common/libkvs/kvs_watch.c:109]: (error) Memory leak: ctx
[src/common/libkvs/kvs_watch.c:363]: (error) va_list 'ap' was opened but
not closed by va_end().
[src/common/libkvs/kvs_watch.c:429]: (error) va_list 'ap' was opened but
not closed by va_end().
  • Loading branch information
garlick committed Jul 14, 2017
1 parent e605530 commit 339bc17
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/common/libkvs/kvs_watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,12 @@ int kvs_watch_once_dir (flux_t *h, kvsdir_t **dirp, const char *fmt, ...)
int rc;

va_start (ap, fmt);
if (vasprintf (&key, fmt, ap) < 0) {
rc = vasprintf (&key, fmt, ap);
va_end (ap);
if (rc < 0) {
errno = ENOMEM;
return -1;
}
va_end (ap);
rc = watch_once_dir (h, key, dirp);
free (key);
return rc;
Expand Down Expand Up @@ -424,11 +425,12 @@ int kvs_watch_dir (flux_t *h, kvs_set_dir_f set, void *arg,
int rc;

va_start (ap, fmt);
if (vasprintf (&key, fmt, ap) < 0) {
rc = vasprintf (&key, fmt, ap);
va_end (ap);
if (rc < ) {
errno = ENOMEM;
return -1;
}
va_end (ap);
rc = watch_dir (h, key, set, arg);
free (key);
return rc;
Expand Down

0 comments on commit 339bc17

Please sign in to comment.