Menu ▾ ▴

#456 example receiveHello crashes with memory fault

3.0.1.0
closed
2445 (2)
2024-05-31
2024-05-29
No

The example receiveHello sometimes crashes with a memory fault when the receive loop begins:

$ ./receiveHello -o 192.168.2.1 -c 40000
...
20240101-02:41:13.326326     Info: tlc_if.c:420 TRDP Stack Version 3.0.24.39(trunk): successfully initiated
20240101-02:41:13.326326     Info: tlc_if.c:424 VOS Version 3.0.0.1(trunk): successfully initiated
...
20240101-02:41:13.331326     Info: tlc_if.c:672 TRDP session opened successfully
Memory fault

The problem seems to be caused by an uninitialzed variable noDesc. The problem disappears after initializing the variable with VOS_INVALID_SOCKET either in receiveHello.c or in tlc_if.c:

--- src/common/tlc_if.c (revision 2439)
+++ src/common/tlc_if.c (working copy)
@@ -1434,6 +1434,7 @@
                 vos_getTime(&now);
                 vos_clearTime(&appHandle->nextJob);


+                *pNoDesc = VOS_INVALID_SOCKET;
                 trdp_pdCheckPending(appHandle, pFileDesc, pNoDesc, TRUE);

 #if MD_SUPPORT

Discussion

  • Armin-Hagen Weiss

    It has to be ensured that the calling application is calling tlc_getIntervall for the first time with NoDesc == VOS_INVALID_SOCKET. For the following calls it is correct to call tlc_getInterva() with the last returned NoDesc.

     
  • Renaat Debaene

    Renaat Debaene - 2024-05-30

    Dear Armin-Hagen,

    OK, that's understood.
    But in that case: multiple examples don't follow this rule. They use declare "INT32 noDesc" in the loop, so this variable is not initialized at all. Suggested patch: move it outside the loop and initialize it.

    Patch for examples receiveHello.c / sendData.c / sendHello.c:

    --- example/receiveHello.c      (revision 2442)
    +++ example/receiveHello.c      (working copy)
    @@ -249,10 +249,10 @@
         /*
          Enter the main processing loop.
          */
    
    +    INT32 noDesc = VOS_INVALID_SOCKET;
         while (1)
         {
             TRDP_FDS_T rfds;
    -        INT32 noDesc;
             TRDP_TIME_T tv = {0, 0};
             const TRDP_TIME_T   max_tv  = {1, 0};
             const TRDP_TIME_T   min_tv  = {0, TRDP_PROCESS_DEFAULT_CYCLE_TIME};
    Index: example/sendData.c
    ===================================================================
    --- example/sendData.c  (revision 2442)
    +++ example/sendData.c  (working copy)
    @@ -288,10 +288,10 @@
         /*
            Enter the main processing loop.
          */
    +    INT32 noDesc = VOS_INVALID_SOCKET;
         while (1)
         {
             TRDP_FDS_T rfds;
    -        INT32 noDesc;
             TRDP_TIME_T tv;
             const TRDP_TIME_T   max_tv  = {1, 0};
             const TRDP_TIME_T   min_tv  = {0, TRDP_PROCESS_DEFAULT_CYCLE_TIME};
    Index: example/sendHello.c
    ===================================================================
    --- example/sendHello.c (revision 2442)
    +++ example/sendHello.c (working copy)
    @@ -312,10 +312,10 @@
         /*
            Enter the main processing loop.
          */
    +    INT32 noDesc = VOS_INVALID_SOCKET;
         while (1)
         {
             TRDP_FDS_T          rfds;
    -        INT32               noDesc;
             TRDP_TIME_T         tv;
             const TRDP_TIME_T   max_tv  = {0, 1000000};
             const TRDP_TIME_T   min_tv  = {0, TRDP_PROCESS_DEFAULT_CYCLE_TIME};
    
     

    Last edit: Renaat Debaene 2024-05-30
  • Armin-Hagen Weiss

    • labels: --> 2445
    • status: open --> closed
    • assigned_to: Armin-Hagen Weiss
     
  • Armin-Hagen Weiss

    All tests/examples handling noDesc now in the same way - definition and initialisation with TRDP_INVALID_SOCKET outside the loop with tlc_getInterval()/voc_select().

     

Log in to post a comment.