Skip to content

Commit

Permalink
Call va_end before returning
Browse files Browse the repository at this point in the history
This is vlm#401 from vlm/asn1c by @Inksz.

From his PR:
I do not know the project's code-style, in some C projects this kind of error-handling would incorporate a goto.
But because of the general avoidance of goto I added va_end before each return.

I suppose has more insight into what this function does, one could "dry" the error handling.
  • Loading branch information
mouse07410 authored Dec 26, 2023
1 parent e4ea3fb commit 57d97b4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion skeletons/asn_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ asn__format_to_callback(int (*cb)(const void *, size_t, void *key), void *key,
if(wrote < (ssize_t)buf_size) {
if(wrote < 0) {
if(buf != scratch) FREEMEM(buf);
va_end(args);
return -1;
}
break;
Expand All @@ -26,11 +27,15 @@ asn__format_to_callback(int (*cb)(const void *, size_t, void *key), void *key,
buf_size <<= 1;
if(buf == scratch) {
buf = MALLOC(buf_size);
if(!buf) return -1;
if(!buf) {
va_end(args);
return -1;
}
} else {
void *p = REALLOC(buf, buf_size);
if(!p) {
FREEMEM(buf);
va_end(args);
return -1;
}
buf = p;
Expand All @@ -39,6 +44,7 @@ asn__format_to_callback(int (*cb)(const void *, size_t, void *key), void *key,

cb_ret = cb(buf, wrote, key);
if(buf != scratch) FREEMEM(buf);
va_end(args);
if(cb_ret < 0) {
return -1;
}
Expand Down

0 comments on commit 57d97b4

Please sign in to comment.