Skip to content

Commit 9496b91

Browse files
committed
fixed some memory leaks
1 parent 0d2033a commit 9496b91

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

error.c

+5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ void error(const char *str, ...)
160160
}
161161

162162
problem(ERROR, str, ap);
163+
va_end(ap);
163164
exit(-1);
164165
}
165166

@@ -178,6 +179,7 @@ void debug(const char *str, ...)
178179
}
179180

180181
problem(DEBUG, str, ap);
182+
va_end(ap);
181183
}
182184

183185
void error_msg(const struct Msg *m, const char *str, ...)
@@ -189,6 +191,7 @@ void error_msg(const struct Msg *m, const char *str, ...)
189191
real_errno = errno;
190192

191193
problem_msg(ERROR, m, str, ap);
194+
va_end(ap);
192195
exit(-1);
193196
}
194197

@@ -201,6 +204,7 @@ void warning(const char *str, ...)
201204
real_errno = errno;
202205

203206
problem(WARNING, str, ap);
207+
va_end(ap);
204208
}
205209

206210
void warning_msg(const struct Msg *m, const char *str, ...)
@@ -212,6 +216,7 @@ void warning_msg(const struct Msg *m, const char *str, ...)
212216
real_errno = errno;
213217

214218
problem_msg(WARNING, m, str, ap);
219+
va_end(ap);
215220
}
216221

217222
static void dump_structs(FILE *out)

info.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void pinfo_addinfo(struct Procinfo *p, int maxsize, const char *line, ...)
4040
va_list ap;
4141

4242
int newchars = p->nchars + maxsize;
43-
void *newptr;
43+
void *newptr = 0;
4444
int res;
4545

4646
va_start(ap, line);
@@ -57,6 +57,7 @@ void pinfo_addinfo(struct Procinfo *p, int maxsize, const char *line, ...)
5757
{
5858
warning("Cannot realloc more memory (%i) in pinfo_addline. "
5959
"Not adding the content.", newmem);
60+
va_end(ap);
6061
return;
6162
}
6263
p->ptr = (char *) newptr;
@@ -65,6 +66,8 @@ void pinfo_addinfo(struct Procinfo *p, int maxsize, const char *line, ...)
6566

6667
res = vsnprintf(p->ptr + p->nchars, (p->allocchars - p->nchars), line, ap);
6768
p->nchars += res; /* We don't store the final 0 */
69+
free(newptr);
70+
va_end(ap);
6871
}
6972

7073
void pinfo_dump(const struct Procinfo *p, int fd)

man.c

+1
Original file line numberDiff line numberDiff line change
@@ -801,5 +801,6 @@ int main() {
801801
".B ts.", tm.tm_year + 1900, tm.tm_mon + 1, TS_MAKE_STR(TS_VERSION), TS_MAKE_STR(TS_VERSION));
802802
#endif
803803
fprintf(f, "%s", manPage);
804+
fclose(f);
804805
return 0;
805806
}

print.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int fd_nprintf(int fd, int maxsize, const char *fmt, ...)
4646
}
4747

4848
free(out);
49-
49+
va_end(ap);
5050
return size;
5151
}
5252

0 commit comments

Comments
 (0)