aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Bolte <matthias.bolte@googlemail.com>2011-04-25 00:25:10 +0200
committerMatthias Bolte <matthias.bolte@googlemail.com>2011-04-30 19:59:52 +0200
commit9ba4eb3c081027846637acf20b17ec801dc66b72 (patch)
tree12eaeebaeeb298f17c8f009d1c08c43a590eda27 /tests/conftest.c
parenttests: Update valgrind suppressions file (diff)
downloadlibvirt-9ba4eb3c081027846637acf20b17ec801dc66b72.tar.gz
libvirt-9ba4eb3c081027846637acf20b17ec801dc66b72.tar.bz2
libvirt-9ba4eb3c081027846637acf20b17ec801dc66b72.zip
tests: Lower stack usage below 4096 bytes
Make virtTestLoadFile allocate the buffer to read the file into. Fix logic error in virtTestLoadFile, stop reading on the first empty line. Use virFileReadLimFD in virtTestCaptureProgramOutput to avoid manual buffer handling.
Diffstat (limited to 'tests/conftest.c')
-rw-r--r--tests/conftest.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/tests/conftest.c b/tests/conftest.c
index a7977bb81..6514f4df5 100644
--- a/tests/conftest.c
+++ b/tests/conftest.c
@@ -6,32 +6,43 @@
#include <string.h>
#include <errno.h>
#include "conf.h"
+#include "memory.h"
-int main(int argc, char **argv) {
- int ret;
+int main(int argc, char **argv)
+{
+ int ret, exit_code = EXIT_FAILURE;
virConfPtr conf;
int len = 10000;
- char buffer[10000];
+ char *buffer = NULL;
if (argc != 2) {
fprintf(stderr, "Usage: %s conf_file\n", argv[0]);
- exit(EXIT_FAILURE);
+ goto cleanup;
}
+ if (VIR_ALLOC_N(buffer, len) < 0) {
+ fprintf(stderr, "out of memory\n");
+ goto cleanup;
+ }
conf = virConfReadFile(argv[1], 0);
if (conf == NULL) {
fprintf(stderr, "Failed to process %s\n", argv[1]);
- exit(EXIT_FAILURE);
+ goto cleanup;
}
- ret = virConfWriteMem(&buffer[0], &len, conf);
+ ret = virConfWriteMem(buffer, &len, conf);
if (ret < 0) {
fprintf(stderr, "Failed to serialize %s back\n", argv[1]);
- exit(EXIT_FAILURE);
+ goto cleanup;
}
virConfFree(conf);
if (fwrite(buffer, 1, len, stdout) != len) {
fprintf(stderr, "Write failed: %s\n", strerror (errno));
- exit(EXIT_FAILURE);
+ goto cleanup;
}
- exit(EXIT_SUCCESS);
+
+ exit_code = EXIT_SUCCESS;
+
+cleanup:
+ VIR_FREE(buffer);
+ return exit_code;
}