471,086 Members | 1,199 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,086 software developers and data experts.

Error: glibc detected and Invalid pointer

hello all i have a code which looks fine when reviewed but when the application has a long run say for example of 2 days it gets exit, because of glibc error and the sample code is as follows:
Expand|Select|Wrap|Line Numbers
  1. while (1)
  2.          {
  3.  
  4.              if((kfp = kd_open(kd_filename, READ, NULL , INIT_YES))== NULL) {
  5.                  printf("%s: File not found ...\n", kd_filename);
  6.                  if (!forceflag) {
  7.                      sleep(5);
  8.                  }
  9.                  else {
  10.                      exit(0);
  11.                  }
  12.              }
  13.             else
  14.              {
  15.                  kd_fileid.capture_session_start_epoch_second = kfp->header.file_id.capture_session_start_epoch_second;
  16.                  kd_fileid.file_sequence_counter = kfp->header.file_id.file_sequence_counter;
  17.  if ( (kfp->header.file_type & END_FILE)== END_FILE )
  18.                      kd_end_flag = 1;
  19.                  else
  20.                      kd_end_flag = 0;
  21.  
  22.                  for(i=0;i<kfp->header.total_packet_count;i++)
  23.                  {
  24.                      if((err=kd_read_next_packet(kfp,(PACKET_t *)kd_row))>0)
  25.                      {
  26.                          pktCount++;
  27.                          pktlen = sizeof(PACKET_HEADER_t) + ((PACKET_t *)kd_row)->kph.kipd.ip_description_str        ing_len + ((PACKET_t *)kd_row)->kph.kipd.ip_packet_len ;
  28.                          send_packets_to_card(kd_row, pktlen);
  29.                      }
  30.                      else
  31.                      {
  32.                          printf("-->%d\n",((PACKET_t *)kd_row)->kph.kipd.ip_packet_len);
  33.                          printf("Error in  File:%d\n",err);
  34.                          break;
  35.                      }
  36.                  }
  37.                  kd_close(kfp, CAPTURE_END);
  38.  
  39.                  if (!forceflag) {
  40.                      if ( (kd_fileid.file_sequence_counter % max_kd_files_per_dir) == 0 ) {
  41.                          dircnt += 1;
  42.                      }
  43.                      kd_fileid.file_sequence_counter += 1;
  44.                      memset((void *)kd_filename, 0, 1024);
  45.                      memset((void *)dir_fname, 0, 512);
  46.                      getdfname(kd_fid, dircnt, kd_fileid.file_sequence_counter, dir_fname);
  47.                      getfilename(kbasedir, dir_fname, kd_filename);
  48.                  }
  49.                  if (kd_end_flag){
  50.                      memcpy(kd_row, FLUSH_SESSION_STR, sizeof(FLUSH_SESSION_STR));
  51.                      printf("Sending Flush sessions command to card\n");
  52.                      send_cntl_cmds_to_card(FLUSH_SESSIONS, FLUSH_SESSION_STR, sizeof(FLUSH_SESSION_STR));
  53.                      return 0;
  54.                  }
  55.              }
  56.              if (forceflag) {
  57.                  break;
  58.              }
  59.          }
  60.          free(kd_row);
  61.          return 0;
  62. }
when the kd_read_next_packet function returns it returns -2 indicating an error condition.Hence the message"Error in file:-2"gets printed and after this i get the message of *** glibc detected *** free(): invalid pointer: 0x0000000000515df0 ***
This will always be in infinite loop the pointer kfp is created on stack.Does the above error suggest that it is due to corruption of pointer kfp or kd_row.these two pointers do not have any problems they are malloced kfp returns a pointer to a file structure which is fine.
May 16 '07 #1
1 2702
AdrianH
1,251 Expert 1GB
Good luck with that. ;)

I've only looked at your code briefly, so I知 not going to comment on its correctness (might not be enough there anyway), however, if you wish to hire me, I値l look in to it further as I知 a contractor.

The problem may be coming from any number of places. In the code you are working on is only one of them (I知 assuming that this is part of a larger system of threads and/or interrupt handlers), but I知 not going to even look at this further without a contract and design schematics (if you have any).


Adrian
May 16 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by alex323 | last post: by
4 posts views Thread by Stian Karlsen | last post: by
reply views Thread by Darrell D. Mobley | last post: by
1 post views Thread by Gary Wessle | last post: by
1 post views Thread by toutnom | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.