• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 789
  • Last Modified:

Debugging Segmentation Fault

Dear Experts

We are getting the segmentation fault error at the following
while(pCust->ases_num == (++pCust_nxt)->ases_num)
The above portion of the code gets called several times during debugging and at some point it fails

When I got the segmentation error , I did print the values of pCust->ases_num which was

(gdb) p pCust->ases_num

$23 = 458778

And (gdb) p (++pCust_nxt)->ases_num

Cannot access memory at address 0x1638

I am putting the detailed information as below

Program received signal SIGSEGV, Segmentation fault.
0x08070cb3 in GenerateFile (iToday=75386, pCust=0x895ca50, pacct=0xbffeae70, acctcntr=2, pbus=0xbffea800,
    paddr=0xbffea660, psesh=0xbffec7a0) at /home/jobby/source/lib/rdb/metronet_report.c:622
622                     while(pCust->ases_num == (++pCust_nxt)->ases_num)
(gdb) bt
#0  0x08070cb3 in GenerateFile (iToday=75386, pCust=0x895ca50, pacct=0xbffeae70, acctcntr=2, pbus=0xbffea800,
    paddr=0xbffea660, psesh=0xbffec7a0) at /home/source/lib/met_report.c:622
#1  0x08070334 in do_mtr (iToday=75386) at /home/source/lib/met_report.c:354
#2  0x0805e7d7 in main (argc=1, argv=0xbffec8f4) at dtr.c:306
#3  0x400bb747 in __libc_start_main () from /lib/libc.so.6
(gdb) p pCust->ases_num
$23 = 458778
(gdb) p (++pCust_nxt)->ases_num
Cannot access memory at address 0x1638
(gdb)

Any help would be highly appritiated
Thank you for your time
Regards
Ronan

0
ronan_40060
Asked:
ronan_40060
3 Solutions
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi ronan_40060,

It's my belief that (++pCust_nxt) is running off the end of the array.  You need to check that the new pointer is valid before trying to dereference it.


Good Luck!
Kent
0
 
btocakciCommented:
The memory you allocated for the array is not large enough to increment pCust_nxt by one. you should realloc() or increase the allocated memory at first when using malloc()..
0
 
srinimsCommented:
invalid memory access, will cause only if the used memory is corrupted one or if it is allocated with the less number of the memory. in some point of time the extra memory access is allowed by the program by accessing the nearest memory which is allocated to the other pointers. But in most of the cases, if the allocated part is end of the particular segment of virtual memory used by the program. it will cause invalid access or segmentation fault. i.e accessing the page having invalid address.

u have to concentrate on the accessed memory is allocated with proper value. and you have to clear enough that you are accessing the memory which is allocated by you only.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ronan_40060Author Commented:
Hello all,
Thanks for your inputs. Today I again compiled the code and ran the application  under a debugged mode , I did not receive any segmentation fault. Im still checking the memory allocated . Will post a comment after I am done.
Thank you for your valuable inputs

regards
Ronan
0
 
ronan_40060Author Commented:
Hello friends

Again I received two segmentation faults at the two places one by one
First I received the Segmentation fault at mycinr.ises_num = pCust->ases_num; as
memory was not accessible for pCust->ases_num so in order to resolve this I used memset
as memset( (char *)pCust, '\0', sizeof(CUST) );

CUST is a structure and pCust is a pointer to a structure CUST.

Still I received a segmentation Fault at memset
Program received signal SIGSEGV, Segmentation fault.
0x40127f9d in memset () from /lib/libc.so.6
What am I doing wrong here
Please let me know
The required part of the code is
---------------------------------------
if ( chxhead.over )  
                                {
memset(&mycinr,0,sizeof(CINR));
memset( (char *)pCust, '\0', sizeof(CUST) );
mycinr.ises_num = pCust->ases_num;
------------------------------------------------
regards
Ronan                        
0
 
srinimsCommented:
pCust has need to be initialized with the size of CUST

like pCust = new char[sizeof(CUST)];
or pCust=(char*)malloc(sizeof(CUST));

before memsetting.

or u might have allocated the same else where, before memsetting u are freed the pCust using the delete[] pCust or free(pCust).

or u have did the wrong assigning or overlap some where else in the program which leading memory leak here.

check other memory operations which are using the PCust.

and other memory pointer which is allocated and used in the concernd limit

srini ms
0
 
ronan_40060Author Commented:
The problem got solved
Thanks all
have a great weekend

Regards
Ronan
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now