We still have raw pointers in the variant and so we need to deal with
copying the contained objects ourselves.
Change-Id: I0e5f1b56430ffeda9d34ede30ec87cfd45a61662
This doesn't yet do much in terms of memory management as it still uses
pointers for arrays and structs, but it does move management of strings
and blobs into the variant. Further refactoring will bring the full
benefits.
Add specialised == operator to avoid implicit conversions to temporary
AmArg.
Includes white space cleanups.
Change-Id: I1e4bce6b96c2187294044f9f2a30fa7013912139
Add missing initialisers and fix order.
In some cases the member was actually unused and could just be removed.
Change-Id: I0f0c927eb8271c35dcfd371f225847f62bea2812
Warned-by: Coverity
These are all instances of an object being put into a container just
before it goes out of scope. Use move semantics to avoid copying.
Change-Id: I9c40a56c4a67df2b8e244d51f068b50ec286f5bf
Warned-by: Coverity
Otherwise we can end up with:
Program terminated with signal SIGSEGV, Segmentation fault.
104 ./core/AmSession.cpp: No such file or directory.
[Current thread is 1 (Thread 0x7fc7dd677e40 (LWP 176249))]
Change-Id: Ia61de0caa9b1764839c740e62bc3f463da4ed4dc
Introduce `ILOG_SDLG()` call-id logging based on
specific getter provided to the macro func as a param.
This is required for those implementations,
where there is no within-file common dialog id getter.
Change-Id: I90501a0da32c7b8075e181796cf4c7c3f980e81e
Make the way we get call-id when calling ILOG_DLG()
file specific, which allows to define locally
(within a target file) how to get the call-id value.
Change-Id: I4af87edf9d1ea52d9678b3354bc797cf1f5f0b54
A fix-up for 3745ff0778d6a55.
This must fix:
Program terminated with signal SIGSEGV, Segmentation fault.
"*\302\3242R \204\vg\266f9\356\277[\252\336J\205\371\020Ŵ\313ٛ\v\231\214\360\355\243\034g\022\001\n\025")
at ./core/sip/sip_parser_async.cpp:205
205 ./core/sip/sip_parser_async.cpp: No such file or directory.
[Current thread is 1 (Thread 0x7f80c07ea6c0 (LWP 3928994))]
(gdb) bt full
"*\302\3242R \204\vg\266f9\356\277[\252\336J\205\371\020Ŵ\313ٛ\v\231\214\360\355\243\034g\022\001\n\025")
at ./core/sip/sip_parser_async.cpp:205
err = 0
c = @0x7f807c001390: 0x7f807c00140e "*\302\3242R \204\vg\266f9\356\277[\252\336J\205\371\020Ŵ\313ٛ\v\231\214\360\355\243\034g\022\001\n\025"
st = @0x7f807c0013a4: 102
saved_st = @0x7f807c0013a8: 0
hdr = 0x0
Change-Id: Icde152783b9dc5a68dde9d29f96d1d87b36e0671
In some cases it can happen that ::join() is called from multiple
threads at the same time. Checking the ::joinable() flag is not
race-free and so is unreliable to make sure that only one other thread
attempts to join at any given time. Add a mutex and a state variable to
make sure only one thread attempts to join, and make any other threads
wait.
Change-Id: I02fd236a416b035c98642535f1521be4a3a63fd9
Fall through so that the shutdown flag gets set and so that the SIP
control sockets get shut down.
Change-Id: I205db4c7aa72dd9576f42b0d9bc2ec4960fd5415
On shutdown, call shutdown() in the socket, so that a thread blocked in
recv() wakes up and gets a chance to exit cleanly.
Change-Id: I24b1b7c608ec1307019b424becef31e8db02e7bb
Zero is a valid file descriptor. Anything that's not -1 can in fact be a
valid file descriptor.
Make sure `sd` is set to -1 whenever no socket is open.
Add dtor to socket class to close the socket if it's open.
Add a few related formatting fixes as well.
Change-Id: Id9d3ad74b986c82ac6ab698a1e8f1f38e0f92414
Classes that inherit from both AmThread and AmEventHandler must inherit
from AmEventQueue first and from AmThread after. This is needed so that
the AmThread dtor is called first, which will trigger the thread to shut
down, which in turn makes sure nothing is waiting on the AmEventQueue's
condition variable.
Otherwise, if AmEventQueue is destroyed first while the corresponding
thread is still running and waiting on the condition variable, it will
be a deadlock.
With this, sems finally can shut down cleanly without having to be
killed by systemd.
Change-Id: I914455763b517c96561acb0b64fce26f127f44bc
Request a thread shutdown in the dtor in case the thread is still
running. Prevents destruction of std::thread with an active thread.
Change-Id: I51c4a43cf8d6402f4a690add936c95c2f700129d
Provide a single place for a running thread to check if it ought to shut
down. Use it in AmThreadWatcher.
Change-Id: I206111b34e3c658f0c2ce55627274b463b1e98d5
Use a std::list instead of a std::queue so that we can use iterators,
which allows us to delete elements directly without having to rebuild a
new queue with every loop iteration. This eliminates the n_thread_queue
and the swap.
Eliminate the wait condition _run_cond. This is only woken up when a
thread is added, which we don't care about. We only care when a thread
finishes, and there is no condition for that.
Use a lock guard. With this we can make sure the lock is in a consistent
state in case of an exception. Still catch and report exceptions.
Remove stub methods.
Change-Id: I59903f6a03863e5c106631e3db8706109915c8fb
Use an atomic enum to track state: idle, running, stopping, or stopped.
Use atomic compare and exchange to ensure consistency without requiring
a mutex.
Never detach threads. Always require a join. This makes for an easy and
reliable way to wait for a thread to finish.
Provide a default on_stop so that it can be omitted in child classes.
Change-Id: Id59942638b7f769090ac91c2049b7d934e876ffc
read() and write() return ssize_t. Update variables and other affected
class members. Pointer arithmetic also returns ssize_t.
Fixes a potential overflow.
Change-Id: I411ad648777fdba5c0fd59f9f7721a2971b60e1d
Warned-by: Coverity
Use overloading for the various flavours of str2int functions. This has
the benefit of automatically choosing the appropriate function for
aliased types that may be one or the other underlying type, such as
size_t.
Do a mass renaming of all relevant instances.
Change-Id: I7abb6b9031ee53332d2b04a6cba4a6cc667a4807
Initialize `from_addr` just setting it all to zero.
Fixes:
*** CID 545189: Uninitialized members (UNINIT_CTOR)
/core/sip/udp_trsp.cpp: 265 in udp_trsp::udp_trsp(udp_trsp_socket *)()
259 msg.msg_name = &from_addr;
260 msg.msg_namelen = sizeof(sockaddr_storage);
261 msg.msg_iov = iov;
262 msg.msg_iovlen = 1;
263 msg.msg_control = dst_addr_buf;
264 msg.msg_controllen = DSTADDR_DATASIZE;
>>> CID 545189: Uninitialized members (UNINIT_CTOR)
>>> Non-static class member "from_addr.__ss_align" is not initialized in this constructor nor in any functions that it calls.
265 }
266
267 udp_trsp::~udp_trsp()
268 {
269 }
270
Change-Id: I7f960e6b41c6d7dfec4f70a91d0e7b37f7675127
Just in case some user still needs the object
to be used through the code later.
E.g.: DBRegAgent module.
Change-Id: Iacd9104edfe757cf475ab25192411103124ed98b
AmThread::stop() detaches the thread, which makes it impossible to
::join() it. Only call one or the other.
Change-Id: Icc9301dc9b31856ec7f963835cffd315bbc925bb
dynamic_cast is used for safe downcasting, so it makes
sense to always ensure whether this cast fails and returns
a null pointer.
Fixes an amount of cases reported by Coverity Scan, alike:
Dynamic cast to pointer dynamic_cast <sip_cseq *>(t->msg->cseq->p) can return NULL.
Assigning: t_cseq = dynamic_cast <sip_cseq *>(t->msg->cseq->p).
Unchecked dynamic_cast (FORWARD_NULL)
Dereferencing null pointer t_cseq.
Change-Id: I5f9bd1a316603ad88b3fdcb2425b4fe8bf99e6a8
Do the dummy read in pieces of 4096. This eliminates the need for a
heap-allocated buffer, which in turn eliminates a possible mem leak.
Change-Id: Ibbbd6f2ef1fa315fad94715c65a74426b3448862
Warned-by: Coverity
Turn objects used by recvmsg() into class members. Eliminates having to
re-initialise them each time.
Change-Id: I9acb6f5f6460c5a9f4c7fb41f8a9e517c7cbbf8b
Warned-by: Coverity
Add cast to make it clear that this is an intentional truncation of a
time_t to an int.
Change-Id: I676f7eb30d4016a531e94975fb230c2d7c9aa9f7
Warned-by: Coverity
If the dlg object is freed, then don't try to log
things based on the call-id value taken from it.
Just do slightly before.
Change-Id: I09e865ca77d64c6c398cf8dc35c189e076fdb26d
Fixes:
Division or modulo by float zero (DIVIDE_BY_ZERO).
divide_by_zero: In function call resampleOutput,
division by expression mixer_sample_rate which may be zero has undefined behavior.
Change-Id: I7f7b8738eb643499dfbf5e830f3904c62ed02b45
Fixes:
cond_cannot_single: Condition output_sample_rate, taking true branch.
Now the value of output_sample_rate cannot be equal to 0.
cannot_single: At condition output_sample_rate,
the value of output_sample_rate cannot be equal to 0
Logically dead code (DEADCODE).
Change-Id: I629cb7fc50b8883a53e7f5cf8d24bd2042b95154
Fixes:
Unchecked return value from library (CHECKED_RETURN).
check_return: Calling fseek(fp, 9L, 0) without checking return value.
This library function may fail and return an error code.
Change-Id: Id7c861a7a78df72968e0755dca47d9a70e736332