开发者

Memory corruption when using SIGALRM and timer

开发者 https://www.devze.com 2023-03-11 13:29 出处:网络
Ok not really sure if it is memory corruption or just a bug in my code, but here is the description of the problem:

Ok not really sure if it is memory corruption or just a bug in my code, but here is the description of the problem: Single threaded program registers a SIGALRM handler:

struct sigaction action;
sigset_t blocked;

sigfillset(&blocked);
sigdelset(&blocked, SIGKILL);
sigdelset(&blocked, SIGSTOP);

action.sa_handler = &handler_function;
action.sa_flags   = SA_RESTART;
action.sa_mask    = blocked;

// We are not interested in 开发者_Go百科the previous action:
if (sigaction(SIGALRM, &action, NULL) == -1)
   ....

handler_function is a simple function which calls a function of an object:

void handler_function()
{
     some_object->tick();
}

tick()
{
    ++variable;
}

Variable is of type long. my program has only one instance of some_object and only signal handler calls function tick and only tick function modifies variable. Other functions only read value of variable. Forgot to mention that I create a timer:

struct timeval interval;
interval.tv_sec   = 0;
interval.tv_usec  = (100000);

struct itimerval timer;
timer.it_interval = interval;
timer.it_value    = interval;
if (setitimer(ITIMER_REAL, &timer, NULL) == -1)
...

so tick function is triggered 10 times per second. Now the problem is that intermittently i get other data members of object some_object corrupted, they are POD types(long), i.e. all of a sudden they contain random values. I've tried to isolate a problem in a small program, but to no avail. Any advise would be appreciated. thanks


There's a buffer overflow in your socket reading code. Fix that and the problem will go away.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号