Re: Crash observed with object on stack but not on heap



On Aug 13, 8:13 pm, ankitmitta...@xxxxxxxxx wrote:
Hi All,

We have multi-threaded application supported on linux. We are
observing very strange behavior related to crash due to this pointer
is getting null.

Let me take snapshot of code..

let us suppose we have 2 classes sample and token
inside any function..
{
sample s1;
token t1;
t1.InstanceFromToken(s1);
Are you trying to Tokenizing String ? <are you using strtok or
strtok_r or simillar.? Is the functions you are trying to use are
Thread Safe ?
there are few functions which provides following clarification in man
pages

<from man strtok_r>
If the character buffer s1 is in dynamic memory, strtok_r() is thread-
safe.
<what if s1 is on array ?, I think it is Crash/corrupted behaviour.>


Hope this helps to find out the root cause and further actions.

-Raxit

}

defenition of InstanceFromToken() looks like..

void token::InstanceFromToken(sample & s)
{
s.function();

}

we are running our servers on 24*7 env and facing crash sometimes.
gdb core stack shows that this pointer is getting null inside
function() API.

so when it tries to use any data member of s class inside function(),
application is getting crash

few strange things are
1. this pointer is getting null.
2.if we check s value inside InstanceFromToken() function, it shows
perfectly in gdb frames,all members are valid
3.This issue is very inconsistent in nature, not reproducible on all
platform like solaris, windows however same code is using there.
4. if we allocate memory of s on heap mean dynamically like sample
s1=new s1() instead of sample s1, problem is no longer reproducible

At this point we are not sure why all these things are happen and more
strangely this pointer is getting null.
Any pointer in this regard is highly usefull and would help to resolve
this issue.


.



Relevant Pages

  • Re: Dealing with HANDLEs
    ... On every new process event this program creates a new Process object and ... pointer and assigns the pointer from the to it. ... This worked in debug. ... Strange, I thought if I pass a pointer, it's like by ref, I can change its ...
    (microsoft.public.win32.programmer.kernel)
  • Re: returning from worker thread
    ... It looks strange that the thread is a member of a file. ... It looks strange that you assign audiofile = pParam inside the loop when pParam will never change. ... The view pointer comes from audiofile->m_pView. ... Perhaps the old thread func received the new pointer each time, but you haven't realized the new thread func receives it only once? ...
    (microsoft.public.vc.mfc)
  • Re: Crash observed with object on stack but not on heap
    ... observing very strange behavior related to crash due to this pointer ... we are running our servers on 24*7 env and facing crash sometimes. ... Put it on the heap and use a heap checker like valgrind or electric fence to find the culprit. ...
    (comp.os.linux.development.apps)
  • Crash observed with object on stack but not on heap
    ... observing very strange behavior related to crash due to this pointer ... we are running our servers on 24*7 env and facing crash sometimes. ... so when it tries to use any data member of s class inside function, ...
    (comp.os.linux.development.apps)
  • Re: Crash observed with object on stack but not on heap
    ... observing very strange behavior related to crash due to this pointer ... we are running our servers on 24*7 env and facing crash sometimes. ... so when it tries to use any data member of s class inside function, ...
    (comp.os.linux.development.apps)