#include <fcntl.h>
#include <unistd.h>
#include <arpa/inet.h>
+#include <stdint.h>
+#include "heap_reap.h"
static unsigned int MESSAGE_SIZE = 1024;
static unsigned int TAG_VER_LEN = 4;
if (usage) pr_usage(usage);
+ heap_and_reap(NULL-1, 0, 0);
exit(EXIT_FAILURE);
}
fprintf(stderr, "%s\nVersion: %0.2f\n%s\n", title, VERSION, copyright);
- if ((model_id = calloc(MODEL_ID_LEN, 1)) == NULL) {
+ if ((model_id = heap_and_reap(NULL, MODEL_ID_LEN, 1)) == NULL) {
pr_error_exit(0, "Unable to allocate memory (%d bytes)\n", MODEL_ID_LEN);
}
memcpy(model_id, match_model_id, MODEL_ID_LEN);
break;
case 'h': // help
pr_usage(1);
- exit(0);
+ goto end;
}
} else {
pr_error_exit(0, "cannot read data from stdin; provide a filename");
if (filename) {
if ((fd = open(filename, fd_mode)) > 0) {
- if ( (buffer = calloc(header_len + sizeof(crc), 1)) != NULL) {
+ if ( (buffer = heap_and_reap(NULL, header_len + sizeof(crc), 1)) != NULL) {
ssize_t qty;
if ( (qty = read(fd, buffer, header_len + sizeof(crc))) < header_len) {
if (!opt_quiet)
);
}
- free(buffer);
+ heap_and_reap(buffer, 0, 0);
close(fd);
} else {
fprintf(stderr, "Unable to open for %s (%s)\n", opt_write ? "writing" : "reading" , filename );
pr_usage(0);
}
+end:
+ heap_and_reap(NULL-1, 0, 0);
return 0;
}