driver: fixed possible leak and use-after-free

log_dest_driver_release_queue() was possibly leaking the LogQueue
instances for file destinations when they got reaped. This was
caused by an earlier patch that fixed a crash in reloads,
more specifically this one: c7070e2a6f1c3a312260bcecf49d62028fef27ce

This patch should fix both cases properly, the leak in the file destination
driver and the original crash in the afsocket destination.

Also, this patch fixes a use-after-free condition, the next member of
a GList structure was referenced after it was removed from the list.

Kudos to Jakub for the detailed bug report and Algernon for the origianl
fix.

Reported-By: Jakub Jankowski <shasta@toxcorp.com>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
Revert "NVTable: allow huge LogMessage data"

This reverts commit bb667115b80b24055dd1245084c7d2e26d01d184.
mainloop: destroying dns-cache and scratch buffers per-thread state doesn't need locking

This patch moves the dns_cache_destroy() and scratch_buffers_free() calls
outside of the protection of main_loop_io_workers_idmap_lock. They
accidentaly got there. Shouldn't be a big performance issue, but
can be a bad example for code added later on.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
mainloop: fixed a minor per-thread leak that occurs when a worker thread exits

This patch frees a per-thread condition variable upon exiting from
worker threads. Worker threads are automatically terminated after 10
seconds of idleness, so this might add up if syslog-ng regularly processes
a message every 10 seconds.

Reported-By: Marvin Nipper <Marvin.Nipper@stream.com>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
log_msg_is_value_name_valid(): new function to check if the passed name is useable as a value name

This function used to live in the rewrite-expr-grammar.ym file, copied here
and a generalized a bit. The other function will go away with the next
commit.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
rewrite-expr-grammar: improve error handling for invalid name-value pair names

This change improves the error handling to better pinpoint the issue
we have with the value() parameter of a given rewrite expression.

Both the invalid .SDATA name and trying to change a read-only macro are
handled the same, with a nice error message.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
throttle: don't let the bucket counter go less than zero

When the LogWriter ignores the throttle setting (for instance when flushing
the destination at reload/exit time), the throttle_buckets can go
below zero, which is unexpected. Don't let that happen.

Signed-off-by: Juhasz Viktor <jviktor@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
preparations for 3.3.5
Merge branch 'upstream/mirror/3.3' into algernon/3.3-merge

Conflicts:
	NEWS
	VERSION
	modules/afmongodb/afmongodb.c
Merge remote-tracking branch 'algernon/algernon/3.4/merge-3.3.5'
NVTable: allow huge LogMessage data

This patch converts NVTable to use 32 bit offsets/sizes in order to allow
maximum 4GB log records, each value holding maximum 4GB data. The NVTable
structure is still artificially limited to 256MB in size.

Signed-off-by: Peter Eisenlohr <peter.eisenlohr@inform-software.com>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
log_expr_node_format_location: fixed a non-zero terminated output string

Instead of sizeof(buf) we should've used the passed buf_len argument. Causes
string not to be properly NUL terminated, or perhaps a buffer overrun in
case the passed buffer is smaller than the size of a pointer.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg-tree: refactor flow-control calculation

Instead of trying to figure out where to put the PIF_HARD_FLOW_CONTROL
bit, defer this to log_pipe_queue(). This makes the compilation code
much easier to understand.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>