Flush request queue to prevent collecting too much data.
Since it is possible for EMMs and ECMs to be removed from
the queues when hard limits are reached, it is a good idea
to clear the request queue too. Without this when queues
reach their hard limits, request queue will grow slowly eating
a bit of memory. It is not much but it is wasted memory.
Do not output anything when there is no valid decryption key.
When the decryption fails due to missing decryption key it is better
to not output anything. Before this patch in case of missing decryption
key the PSI tables were still being written to the output and this
could confuse some monitoring systems to think that the stream is
working.
Technically this is not right because the first char sets the
charset (eg 0x05 -> ISO-8859-5) but since tsdecrypt have no business
handling charsets just replace all special chars with asterisks.
This time free the memory returned by crypt() only once. This way
the leak is avoided and also double free error is avoided also.
The patch fixes the following valgrind compaint:
43 bytes in 1 blocks are still reachable in loss record 1 of 1
at 0x4026844: malloc (vg_replace_malloc.c:263)
by 0x40268BE: realloc (vg_replace_malloc.c:632)
by 0x41EE411: __md5_crypt (in /lib/libcrypt-2.13.so)
by 0x41EDA56: crypt (in /lib/libcrypt-2.13.so)
by 0x805F702: newcamd_login (camd-newcamd.c:297)
by 0x9F0B10: ???
Without this if the input is MPTS, tsdecrypt incorrectly tries to
decrypt (and brokes) services that do not belong to the chosen
input services. An additional extra is that with this decrypting
a service in MPTS is a lot quicker since lots of unneeded work is
avoided.