]> pd.if.org Git - zpackage/blob - lib/seterror.c
fix possible memory leak in uncompress
[zpackage] / lib / seterror.c
1 #define _POSIX_C_SOURCE 200809L
2
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <stdarg.h>
6 #include <string.h>
7
8 #include "zpm.h"
9
10 void zpm_seterror(struct zpm *zpm, char *msgfmt, ...) {
11         char msg[1024];
12         va_list ap;
13
14         if (zpm->errmsg) {
15                 free(zpm->errmsg);
16                 zpm->errmsg = 0;
17         }
18
19         if (msgfmt != NULL) {
20                 va_start(ap, msgfmt);
21                 vsnprintf(msg, sizeof msg, msgfmt, ap);
22                 va_end(ap);
23
24                 msg[1023] = 0;
25                 if (zpm->errmsg) {
26                         free(zpm->errmsg);
27                 }
28
29                 zpm->errmsg = strdup(msg);
30         }
31 }