diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-12-29 01:35:09 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-12-29 01:35:09 -0500 |
commit | 4595ada2f69b42670c85a63c7d2344af63f2afe7 (patch) | |
tree | 0d528d8177aceefcf74fb7306fc0fc7cc3c41ece /src/shell.c | |
parent | 8ae4f8f5985445b1ce3547975f407847c0fee0f7 (diff) | |
download | spmc-4595ada2f69b42670c85a63c7d2344af63f2afe7.tar.gz |
Minor fixes:
* size_t in place of int
* Moved some variables closer to their execution scope
* Add some error checks
Diffstat (limited to 'src/shell.c')
-rw-r--r-- | src/shell.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/shell.c b/src/shell.c index 6ce3ad2..6b28e64 100644 --- a/src/shell.c +++ b/src/shell.c @@ -32,9 +32,6 @@ void shell(Process **proc_info, u_int64_t option, const char *fmt, ...) { va_list args; va_start(args, fmt); - size_t bytes_read = 0; - size_t i = 0; - size_t new_buf_size = 0; clockid_t clkid = CLOCK_REALTIME; FILE *proc = NULL; @@ -68,6 +65,8 @@ void shell(Process **proc_info, u_int64_t option, const char *fmt, ...) { proc = popen(cmd, "r"); if (!proc) { + free(outbuf); + va_end(args); return; } @@ -81,10 +80,12 @@ void shell(Process **proc_info, u_int64_t option, const char *fmt, ...) { } if (option & SHELL_OUTPUT) { + size_t bytes_read = 0; + size_t i = 0; + size_t new_buf_size; (*proc_info)->output = (char *)calloc(BUFSIZ, sizeof(char)); while ((*outbuf = fgetc(proc)) != EOF) { - if (i >= BUFSIZ) { new_buf_size = BUFSIZ + (i + bytes_read); (*proc_info)->output = (char *)realloc((*proc_info)->output, new_buf_size); |