summarylogtreecommitdiffstats
path: root/lua.patch
blob: d71bbd768293af8b0e97c6f563ece60651f0be98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
--- src/luahooks.c.1	2013-05-02 20:30:23.000000000 +0000
+++ src/luahooks.c	2013-08-29 05:24:54.088977360 +0000
@@ -24,6 +24,16 @@
 
 static lua_State *lua;
 
+static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize)
+{
+  if (nsize == 0) {
+    free(ptr);
+    return NULL;
+  } else {
+    return realloc(ptr, nsize);
+  }
+}
+
 static luahook_action_t
 string_to_luahook_action (const char * s)
 {
@@ -144,7 +154,7 @@
   if (opt.lua_filename == NULL)
     return;
 
-  lua = lua_open ();
+  lua = lua_newstate (l_alloc, NULL);
   luaL_openlibs (lua);
 
   /* Initialize constants. */
@@ -460,7 +470,7 @@
         return NULL;
 
       /* Copy to the buffer. */
-      size_t ret_l = lua_strlen(lua, -1);
+      size_t ret_l = lua_rawlen(lua, -1);
       ret_l = (ret_l <= MAX_HOST_LENGTH) ? ret_l : MAX_HOST_LENGTH;
       strncpy (lookup_host_result, ret, ret_l);