开发者

Programming / memory / logical issue in code

Can you tell me is there any thing wrong in the code, my application is crashing randomly I cannot find any possible logical or memory error, please help as this is going out of my scope.

#define __FN__ "CGD9_gd_ParseAddFieldsProC"
int CGD9_gd_ParseAddFieldsProC (CGD_gd_ParseAddFields_Iparam_t *i_param_st_p)
{

   t_gd9adfld_t *p_ext_fields_s = NULL;
   t_gd9sbdat_t *p_buff =
                  ( t_gd9sbdat_t * )( i_param_st_p->i_add_fields_st );

   Trace(__FN__);

   DEBUG_GD_1("\n\n Function %s - started. \n\n", __FN__);

   if(*(i_param_st_p->o_add_fields) == NULL) {
     ERR_Report_1(DGD_ERR_IN_FUNCTION,
     __FN__ "ERROR - program will crash, input extended struct\
has not been initialized!");

     ERR_Report_1(DGD_ERR_IN_FUNCTION, __FN__\
"Check that exit point CMI9_auxc_A_GUIDING_init_forProc \
is used in GD table!");

    fflush(NULL);
    return FAILURE;
   }

   p_ext_fields_s = *(i_param_st_p->o_add_fields);

   memset ( p_ext_fields_s, ' ', sizeof (t_gd9adfld_t));

/* Copy all extended fields from GD tables to buffer one by one*/

        memcpy(&p_ext_fields_s->rowid,
          &p_buff[i_param_st_p->output_index].rowid,
          sizeof(p_buff[i_param_st_p->output_index].rowid));

    memset(p_ext_fields_s->rowid,'0',18);


        memcpy(&开发者_JAVA百科;p_ext_fields_s->l9_legacy_prod_type,
          &p_buff[i_param_st_p->output_index].l9_legacy_prod_type,
          sizeof(p_ext_fields_s->l9_legacy_prod_type));


   /* Free the memory allocated for extended fields */

   free(i_param_st_p -> i_add_fields_st);
   i_param_st_p -> i_add_fields_st = NULL;

   DEBUG_GD_1("\n\n Function %s - completed successuflly. \n\n", __FN__);

   return SUCCESS;
}


Shot in the dark:

You're using

memcpy(&p_ext_fields_s->rowid ...

but

memset(p_ext_fields_s->rowid,...

So perhaps it should be

memset(&p_ext_fields_s->rowid,

instead? But if this really was the problem, I would expect it to not randomly crash, but crash every single time...


Why do you use sizeof() in the first case and then constant size (18) in the second?

memcpy(&p_ext_fields_s->rowid,
  &p_buff[i_param_st_p->output_index].rowid,
  sizeof(p_buff[i_param_st_p->output_index].rowid));

memset(p_ext_fields_s->rowid,'0',18);

PS I'd propose run your code with memory checking tool (as I suspect memory corruptions).


The code is crashing to free memory allocation:

free(i_param_st_p -> i_add_fields_st); 

What is wrong in tht :< ?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜