Merge pull request #55 from Qingtao-Cao/devel

Devel
Merge pull request #56 from Qingtao-Cao/devel

Devel
Merge pull request #59 from Qingtao-Cao/devel

Devel
Merge pull request #62 from Qingtao-Cao/devel

Devel
Switch to using memcpy to avoid strict aliasing rule errors in GCC 4.4
Fix whitespace to conform with standards
Fix whitespace properly
Merge pull request #64 from Qingtao-Cao/devel

No regression could have been introduced since there is no change about the prototypes or data flow of the oBIX server functions regarding XML file or memory parsing. In theory it is a good start to replace xmlParsexxx with xmlReadxxx and we can further optimse oBIX server memory usage about XML parser dictionary in the future.

Merged given that all valgrind tests passed.
Merge pull request #63 from dfj/devel

Switch to using memcpy to avoid strict aliasing rule errors in GCC 4.4
Fix a race condition in ptask_dispose

After ptask_dispose invokes ptask_schedule to insert a special
stopTask into the task queue of the specified thread, that thread
may be scheduled in immediately after ptask_dispose unlocks the
mutex protecting the whole task queue, resulting in the whole
thread including the whole task queue destroyed before they are
accessed by ptask_dispose. Relevant valgrind reports are as below.

The solution is straightforward. If the to-be-scheduled task is
stopTask, then refrain from accessing relevant ptask descriptor
nor the thread descriptor, since they may have been deleted already.
If needed, a copy of the PID of the current worker thread could be
saved and accessed later.

==20553== Invalid read of size 4
==20553==    at 0x4C415C4: ptask_schedule (ptask.c:493)
==20553==    by 0x4C41A51: ptask_dispose (ptask.c:662)
==20553==    by 0x4C41B7C: obix_destroy_task (ptask.c:701)
==20553==    by 0x403CED: mg_destroy_modbus (mg_adaptor.c:1043)
==20553==    by 0x404117: mg_destroy_mg (mg_adaptor.c:1153)
==20553==    by 0x406CC1: main (mg_adaptor.c:2302)
==20553==  Address 0x529aee0 is 0 bytes inside a block of size 88 free'd
==20553==    at 0x4A074C4: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==20553==    by 0x4C41192: periodicTask_free (ptask.c:285)
==20553==    by 0x4C41376: periodicTask_deleteRecursive (ptask.c:388)
==20553==    by 0x4C414B1: stopTask (ptask.c:463)
==20553==    by 0x4C4124E: periodicTask_execute (ptask.c:320)
==20553==    by 0x4C41448: threadCycle (ptask.c:444)
==20553==    by 0x3208A07C52: start_thread (pthread_create.c:308)
==20553==    by 0x32082F5DBC: clone (clone.S:113)
==20553==
==20553== Invalid read of size 8
==20553==    at 0x4C41A6A: ptask_dispose (ptask.c:667)
==20553==    by 0x4C41B7C: obix_destroy_task (ptask.c:701)
==20553==    by 0x403CED: mg_destroy_modbus (mg_adaptor.c:1043)
==20553==    by 0x404117: mg_destroy_mg (mg_adaptor.c:1153)
==20553==    by 0x406CC1: main (mg_adaptor.c:2302)
==20553==  Address 0x50e1b50 is 16 bytes inside a block of size 160 free'd
==20553==    at 0x4A074C4: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==20553==    by 0x4C41509: stopTask (ptask.c:471)
==20553==    by 0x4C4124E: periodicTask_execute (ptask.c:320)
==20553==    by 0x4C41448: threadCycle (ptask.c:444)
==20553==    by 0x3208A07C52: start_thread (pthread_create.c:308)
==20553==    by 0x32082F5DBC: clone (clone.S:113)
Avoid -Werror=maybe-uninitialized type of error.

Once "-O3" or "-O4" option is applied, gcc will detect further
maybe-uninitialised type of error. It doesn't hurt to initialise
the variable in advance.
Fix remaining whitespace errors in previous patch for bms_adaptor.c

Two tabs (of 4 whitespaces each) are preferred to 8 consecutive
whitespaces.