Core dump caused by a corrupted shared memory

Viewed 27

i have this git repository where i put the full code. If you run it could see (now) that print strange value when resume the value stored in node's shared memory. I found out that i remove(put comment) on :

user_manager.c row 37 function removeTransaction

It terminate successfully but without the correct calulation cause by the TransactinPool full and never free of the transaction in the shared memory(Masterbook) that should be eliminated in the local memory(TransactionPool) one elaborated by node. But i need it cause when an user receive it, delete the Transaction elaborated, so that can make another transaction. I didn't find a way to figure out why the value in shared memory(only Node) change. Cause i access it only in read, i never change value of nodeList[ID].pid

EDIT: i cannot post full code and a minimun reproducible code cause is too big and the problem is showed up only in this funcionts. Why if i use this the shared memory seems to be corrupted while in this funciotns no rows modify it??

int searchTransaction(struct Transaction transaction)
{
    int res = -1;
    for (int i = 0; i < sizePool; i++)
    {
        if (strcmp(transaction_pool[i].timestamp, transaction.timestamp) == 0 && (transaction_pool[i].sender == transaction.sender) && (transaction_pool[i].receiver == transaction.receiver)){
                res = i;
                break;
            }
    }
    return res;
}

int removeTransaction(struct Transaction transaction)
{
    
    if(transaction.empty!=1) {
        printTransaction(transaction);
        printf("\nError in removeTransaction: transaction empty! %d",getpid());
          return -1;
    }
    int pos = searchTransaction(transaction);
    if (pos < 0){
        printf("\nError in removeTransaction: transaction not found! %d",getpid());
        return -1;          
    }
    
    for (int i = pos; i < sizePool - 1; i++)
    {
        transaction_pool[i] = transaction_pool[i + 1];
    }
    --sizePool;
    transaction_pool = realloc(transaction_pool,sizePool * sizeof(struct Transaction));
    
    return 0;
}
0 Answers
Related