lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi lua-l
 i create a thread using __beginthread and in this thread i open the lua:
if( 0 != pUS->script_path[0] ){
  pUS->L = luaL_newstate();
  luaL_openlibs(pUS->L);
  //MessageBox(NULL,TEXT("BP1-2"),DEBUG,NULL);
  luaL_loadfile(pUS->L,pUS->script_path);
  //MessageBox(NULL,TEXT("BP1-3"),DEBUG,NULL);
  lua_pcall(pUS->L,0,0,0);
 }
in this thread i using lua to process the string, and all goes well,
after i allocate a memory block using malloc in thread :
if( NULL != pUS->L ){
    lua_getglobal(pUS->L,"process");
    lua_pushstring(pUS->L,rhd.pdata);
    lua_pcall(pUS->L,1,1,0);
    memset(rhd.pdata,0,MAX_BUFFER_SIZE);
    strcpy(rrhd.pdata,lua_tostring(pUS->L,-1));
    rrhd.ori_len = strlen(rrhd.pdata);
   }
   pUS->prhd[pUS->rhd_rear].ori_len = rrhd.ori_len;
   pUS->prhd[pUS->rhd_rear].pdata = (char *)malloc(sizeof(char)*rrhd.ori_len);
   memcpy(pUS->prhd[pUS->rhd_rear].pdata ,rrhd.pdata,sizeof(char)*rrhd.ori_len);
   pUS->rhd_rear = (pUS->rhd_rear+1)%1000;
the lua_close crash down the app( power off kind)...
I send a email previous about the luaM_freearray causing the problem and now , i found that is lua_close. It cloud not
close successfully. If i commented the allocate code , lua_close successfully.