x509: Add __gc to free X509 object on destruction

Sat, 06 Nov 2010 13:04:09 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 06 Nov 2010 13:04:09 +0000
changeset 25
4bc25168aa1c
parent 24
bbf12f9be71c
child 26
bbff42d46512

x509: Add __gc to free X509 object on destruction

src/x509.c file | annotate | diff | comparison | revisions
--- a/src/x509.c	Sat Nov 06 01:10:01 2010 +0000
+++ b/src/x509.c	Sat Nov 06 13:04:09 2010 +0000
@@ -258,6 +258,12 @@
   return 1;
 }
 
+int meth_destroy(lua_State* L)
+{
+  X509_free(luasec_to_x509(L, 1));
+  return 0;
+}
+
 /**
  * Certificate metamethods
  */
@@ -278,7 +284,8 @@
   lua_newtable(L);
   luaL_register(L, NULL, meta);
   lua_setfield(L, -2, "__index");
-
+  lua_pushcfunction(L, meth_destroy);
+  lua_setfield(L, -2, "__gc");
   lua_newtable(L);
   return 1;
 }

mercurial