Drop event_t, use a character buffer in main(). Memory allocation/deallocation becomes an internal matter of queue.c instead of the current transfers of memory ownership on enqueue() and peek_queue(). Index: audit/audisp/plugins/remote/audisp-remote.c =================================================================== --- audit.orig/audisp/plugins/remote/audisp-remote.c +++ audit/audisp/plugins/remote/audisp-remote.c @@ -340,7 +340,6 @@ static void do_overflow_action(void) int main(int argc, char *argv[]) { - event_t *e; struct sigaction sa; int rc, q_len; @@ -383,6 +382,7 @@ int main(int argc, char *argv[]) do { fd_set rfd; struct timeval tv; + char event[MAX_AUDIT_MESSAGE_LENGTH]; int n, fds = ifd + 1; /* Load configuration */ @@ -428,8 +428,7 @@ int main(int argc, char *argv[]) if (hup != 0 || stop != 0) continue; - e = (event_t *)malloc(sizeof(event_t)); - if (fgets_unlocked(e->data, MAX_AUDIT_MESSAGE_LENGTH, in)) { + if (fgets_unlocked(event, sizeof(event), in)) { if (!transport_ok && remote_ended && config.remote_ending_action == FA_RECONNECT) { quiet = 1; @@ -438,25 +437,20 @@ int main(int argc, char *argv[]) quiet = 0; } /* Strip out EOE records */ - if (strstr(e->data,"type=EOE msg=audit(")) { - free(e); + if (strstr(event,"type=EOE msg=audit(")) continue; - } - if (enqueue(e) != 0) + if (enqueue(event) != 0) do_overflow_action(); rc = 0; while (!suspend && rc >= 0 && transport_ok && - (e = peek_queue()) != NULL) { - rc = relay_event(e->data, - strnlen(e->data, + peek_queue(event, sizeof(event)) != 0) { + rc = relay_event(event, + strnlen(event, MAX_AUDIT_MESSAGE_LENGTH)); - if (rc >= 0) { - free(e); + if (rc >= 0) dequeue(); // delete it - } } - } else - free(e); + } if (feof(in)) break; } while (stop == 0); Index: audit/audisp/plugins/remote/queue.c =================================================================== --- audit.orig/audisp/plugins/remote/queue.c +++ audit/audisp/plugins/remote/queue.c @@ -600,43 +600,32 @@ int init_queue(remote_conf_t *config) return 0; } -int enqueue(event_t *e) +int enqueue(const char *data) { - int ret; - - if (q_append(q, e->data) == 0) - ret = 0; + if (q_append(q, data) == 0) + return 0; else if (errno == ENOSPC) - ret = -1; + return -1; else { queue_error(); - ret = 0; + return 0; } - free(e); - return ret; } -event_t *peek_queue(void) +int peek_queue(char *buf, size_t size) { - event_t *e; int r; - e = malloc(sizeof(*e)); - if (e == NULL) - goto err; - r = q_peek(q, e->data, sizeof(e->data)); - if (r == 0) { - free(e); - return NULL; - } + r = q_peek(q, buf, size); + if (r == 0) + return 0; if (r != 1) goto err; - return e; + return 1; err: queue_error(); - free(e); - return NULL; + return 0; } void dequeue(void) Index: audit/audisp/plugins/remote/queue.h =================================================================== --- audit.orig/audisp/plugins/remote/queue.h +++ audit/audisp/plugins/remote/queue.h @@ -28,15 +28,9 @@ #include "libaudit.h" #include "remote-config.h" -typedef struct event -{ - char data[MAX_AUDIT_MESSAGE_LENGTH]; -} event_t; - - int init_queue(remote_conf_t *config); -int enqueue(event_t *e); -event_t *peek_queue(void); +int enqueue(const char *data); +int peek_queue(char *buf, size_t); void dequeue(void); int queue_length(void); void destroy_queue(void);