Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 643ad19a61fa7c87021bec75ace7b2d7ce65163f
Ticket: 1726873fffffffffffffffffffffffffffffffff
Intermittent crash in threaded Tcl
User & Date: afredd on 2007-05-29 23:11:19
Changes

  1. icomment:
    Logged In: YES 
    user_id=1386588
    Originator: NO
    
    
    Interesting problem. Just skimmed thro' tclthread.c and
    noticed that RememberSyncObject() does not check the list for
    free slots before alloc'ing a new list ie. it can grow unnecesarily
    and unbounded. Although you'd have hit a malloc failure
    long before the "recPtr->max += 8" wrapped... :-\
    Anyway this patch at the top of that function might help:
    
    +    /* Check for a free NULL slot in the list (if it has been allocated) */
    +    if (recPtr->list != NULL) {
    +       for (i = 0; i < recPtr->num; ++i) {
    +           if (recPtr->list[i] == NULL) {
    +               recPtr->list[i] = objPtr;
    +               return;
    +           }
    +       }
    +    }
    +
    
    
    Also if you think that there may be a memory corruption,
    you could try something like (untested):
    
     typedef struct {
    +    int guard1;                /* memory corruption guard */
         int num;           /* Number of objects remembered */
    +    int guard2;                /* memory corruption guard */
         int max;           /* Max size of the array */
    +    int guard3;                /* memory corruption guard */
         char **list;       /* List of pointers */
    +    int guard4;                /* memory corruption guard */
     } SyncObjRecord;
    
    -static SyncObjRecord keyRecord = {0, 0, NULL};
    -static SyncObjRecord mutexRecord = {0, 0, NULL};
    -static SyncObjRecord condRecord = {0, 0, NULL};
    +#define GX 0xbbbbbbbb /* the value in the guard fields */
    +
    +static SyncObjRecord keyRecord   = {GX, 0, GX, 0, GX, NULL, GX};
    +static SyncObjRecord mutexRecord = {GX, 0, GX, 0, GX, NULL, GX};
    +static SyncObjRecord condRecord  = {GX, 0, GX, 0, GX, NULL, GX};
    
    If the guard values have changed when the crash occurs you
    know something's scrawled over memory.
    
    Good luck!
    
    
    
  2. login: "afredd"
  3. mimetype: "text/plain"
  4. username: "afredd"