diff options
author | Lutz Helwing <lutz_helwing@mentor.com> | 2015-10-09 14:34:19 +0200 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2015-10-28 11:37:32 +0100 |
commit | fb99b7875dfe64a4073aa14f33c551098632847c (patch) | |
tree | d771a7287e00b9dcedb3f94281cfdcb58d306a0e /src/tests/dlt-test-init-free.c | |
parent | a65dcd34513308b37165f8544ab647016d6e7209 (diff) | |
download | DLT-daemon-fb99b7875dfe64a4073aa14f33c551098632847c.tar.gz |
Purged all warnings for -Wall -Wextra
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Diffstat (limited to 'src/tests/dlt-test-init-free.c')
-rw-r--r-- | src/tests/dlt-test-init-free.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/tests/dlt-test-init-free.c b/src/tests/dlt-test-init-free.c index d299938..81083e3 100644 --- a/src/tests/dlt-test-init-free.c +++ b/src/tests/dlt-test-init-free.c @@ -27,11 +27,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <stdbool.h> #include "dlt_common.h" #include "dlt_user.h" -char* exec(const char* cmd); +void exec(const char* cmd, char *buffer, size_t length); void printMemoryUsage(); char* occupyMemory(uint size); void do_example_test(); @@ -110,32 +111,28 @@ void do_dlt_test() } } -char* exec(const char* cmd) +void exec(const char* cmd, char *buffer, size_t length) { - FILE* pipe = popen(cmd, "r"); - if (!pipe) - return "ERROR"; + FILE* pipe = NULL; + strncpy(buffer, "ERROR", length); - char* buffer = (char*)malloc(128); - while (!feof(pipe)) - { - fgets(buffer, 128, pipe); - } - pclose(pipe); + if ( (pipe = popen(cmd, "r")) == NULL ) + return; + + while (fgets(buffer, length, pipe) != NULL); - return buffer; + if(pipe != NULL) + pclose(pipe); } void printMemoryUsage() { - char command[128] = "pmap "; + char result[128] = { 0 }; + char command[128] = { 0 }; - char buf[128]; - snprintf(buf, sizeof(command), "%d", getpid()); - strcat(command, buf); - strcat(command, " | grep total"); + snprintf(command, sizeof(command), "pmap %d | grep total", getpid()); - char* result = exec(command); + exec(command, result, sizeof(result)); printf("%s", result); } |