/*! A helper function for freeExpr and freeExprNR @param expr the expression to free from memory @param next whether to free the next expression as well as the given one @return 0 */ static bool freeExpr_ (expression* expr, bool next) { if (expr != NULL) { // if the expression isn't null exprvals ev = expr->ev; switch (expr->type) { // depending on the expression's type case TYPE_EXP: freeExpr(ev.expval); // recursively call this function with the expression's child expression break; case TYPE_LAZ: freeLaz(ev.lazval); break; case TYPE_STR: freeStr(ev.strval); break; case TYPE_ARR: freeArr(ev.arrval); break; case TYPE_OBJ: freeObj(ev.objval); case TYPE_FUN: freeFun(ev.funval); break; } if (next) { // if the next expression should be freed freeExpr(expr->next); // recursively call this function with the expression's next expression } free(expr); // free the expression itself } return 0; }
void freeWrapper(void *p) { freeFun(p); fprintf(stderr,"free(%p)\n",p); }