--- lua-5.3.4/src/lapi.c.orig 2019-06-03 17:29:46.376205064 +0200 +++ lua-5.3.4/src/lapi.c 2019-06-03 17:31:08.869905663 +0200 @@ -1289,6 +1289,8 @@ LClosure *f1; UpVal **up1 = getupvalref(L, fidx1, n1, &f1); UpVal **up2 = getupvalref(L, fidx2, n2, NULL); + if (*up1 == *up2) + return; luaC_upvdeccount(L, *up1); *up1 = *up2; (*up1)->refcount++;