Changeset d221460a632fc089092b34dcfb215f8296a9b713

Show
Ignore:
Timestamp:
08/03/08 19:06:58 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1217790418 +0000
git-parent:

[fda4621228eace5666578fde08eceae320d9100b]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1217790418 +0000
Message:

supposedly garbage collecting the coro should be enough to do the trick -- resuming it causes accessing freed memory (due to the gc), refs #47

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/lua.c

    rfda4621 rd221460  
    4646} 
    4747 
     48void 
     49cancel_coro(noit_lua_check_info_t *ci) { 
     50  lua_getglobal(ci->lmc->lua_state, "noit_coros"); 
     51  luaL_unref(ci->lmc->lua_state, -1, ci->coro_state_ref); 
     52  lua_pop(ci->lmc->lua_state, 1); 
     53  lua_gc(ci->lmc->lua_state, LUA_GCCOLLECT, 0); 
     54  noit_hash_delete(&noit_coros, 
     55                   (const char *)&ci->coro_state, sizeof(ci->coro_state), 
     56                   NULL, NULL); 
     57} 
     58 
    4859noit_lua_check_info_t * 
    4960get_ci(lua_State *L) { 
    5061  noit_lua_check_info_t *v = NULL; 
    51   if(noit_hash_retrieve(&noit_coros, (const char *)&L, sizeof(L), (void **)&v)) { 
     62  if(noit_hash_retrieve(&noit_coros, (const char *)&L, sizeof(L), (void **)&v)) 
    5263    return v; 
    53   } 
    5464  return NULL; 
    5565} 
     
    495505int 
    496506noit_lua_resume(noit_lua_check_info_t *ci, int nargs) { 
    497   int result, base; 
     507  int result = -1, base; 
    498508  noit_check_t *check; 
    499509  check = ci->check; 
     
    528538      break; 
    529539  } 
    530   lua_getglobal(ci->lmc->lua_state, "noit_coros"); 
    531   luaL_unref(ci->lmc->lua_state, -1, ci->coro_state_ref); 
    532   lua_pop(ci->lmc->lua_state, 1); 
    533   lua_gc(ci->lmc->lua_state, LUA_GCCOLLECT, 0); 
     540  cancel_coro(ci); 
    534541 
    535542  noit_lua_log_results(ci->self, ci->check); 
     
    555562     * it, garbage collect it and then ensure that it failes a resume 
    556563     */ 
    557     lua_getglobal(ci->lmc->lua_state, "noit_coros"); 
    558     luaL_unref(ci->lmc->lua_state, -1, ci->coro_state_ref); 
    559     lua_pop(ci->lmc->lua_state, 1); 
    560     lua_gc(ci->lmc->lua_state, LUA_GCCOLLECT, 0); 
    561     assert(2 == noit_lua_resume(ci, 0)); 
    562   } else { 
    563     noit_lua_log_results(ci->self, ci->check); 
    564     noit_lua_module_cleanup(ci->self, ci->check); 
    565     check->flags &= ~NP_RUNNING; 
    566   } 
     564    cancel_coro(ci); 
     565  } 
     566 
     567  noit_lua_log_results(ci->self, ci->check); 
     568  noit_lua_module_cleanup(ci->self, ci->check); 
     569  check->flags &= ~NP_RUNNING; 
     570 
    567571  if(int_cl->free) int_cl->free(int_cl); 
    568572  return 0; 
     
    570574static int 
    571575noit_lua_initiate(noit_module_t *self, noit_check_t *check) { 
    572   lua_State **coro_state_copy; 
    573576  LMC_DECL(L, self); 
    574577  struct nl_intcl *int_cl; 
     
    606609  eventer_add(e); 
    607610 
    608   noitL(nldeb, "initiate gettop => %d\n", lua_gettop(L)); 
    609611  ci->lmc = lmc; 
    610612  lua_getglobal(L, "noit_coros"); 
     
    612614  ci->coro_state_ref = luaL_ref(L, -2); 
    613615  lua_pop(L, 1); /* pops noit_coros */ 
    614  
    615   coro_state_copy = malloc(sizeof(*coro_state_copy)); 
    616   *coro_state_copy = ci->coro_state; 
    617   noit_hash_replace(&noit_coros, 
    618                   (const char *)coro_state_copy, sizeof(*coro_state_copy), 
    619                   ci, free, NULL); 
     616  noit_hash_store(&noit_coros, 
     617                  (const char *)&ci->coro_state, sizeof(ci->coro_state), 
     618                  ci); 
    620619 
    621620  SETUP_CALL(ci->coro_state, "initiate", goto fail);