]> granicus.if.org Git - neomutt/commitdiff
allocate Buffer in lua_mutt_enter()
authorRichard Russon <rich@flatcap.org>
Fri, 12 Apr 2019 10:38:15 +0000 (11:38 +0100)
committerRichard Russon <rich@flatcap.org>
Tue, 16 Apr 2019 10:09:54 +0000 (11:09 +0100)
mutt_lua.c

index 602609f8d4a672853ab40fa5b85180335cc37c86..912c83fbb11fffc6cecf74237353ae7a7d87701e 100644 (file)
@@ -288,31 +288,27 @@ static int lua_mutt_get(lua_State *l)
 static int lua_mutt_enter(lua_State *l)
 {
   mutt_debug(LL_DEBUG2, " * lua_mutt_enter()\n");
-  struct Buffer token, err;
+  struct Buffer *err = mutt_buffer_pool_get();
+  struct Buffer *token = mutt_buffer_pool_get();
   char *buf = mutt_str_strdup(lua_tostring(l, -1));
   int rc = 0;
 
-  mutt_buffer_init(&err);
-  mutt_buffer_init(&token);
-
-  err.dsize = 256;
-  err.data = mutt_mem_malloc(err.dsize);
-
-  if (mutt_parse_rc_line(buf, &token, &err))
+  if (mutt_parse_rc_line(buf, token, err))
   {
-    luaL_error(l, "NeoMutt error: %s", err.data);
+    luaL_error(l, "NeoMutt error: %s", mutt_b2s(err));
     rc = -1;
   }
   else
   {
-    if (!lua_pushstring(l, err.data))
+    if (!lua_pushstring(l, mutt_b2s(err)))
       handle_error(l);
     else
       rc++;
   }
 
   FREE(&buf);
-  FREE(&err.data);
+  mutt_buffer_pool_release(&token);
+  mutt_buffer_pool_release(&err);
 
   return rc;
 }