From 7f7c5eb7d847ea403a604fa1811373e9be7003bc Mon Sep 17 00:00:00 2001
From: "Dmitry E. Oboukhov" <unera@debian.org>
Date: Thu, 13 Jun 2013 17:08:05 +0400
Subject: [PATCH] Copy error string to lua buffer before exception.

---
 src/lua/mysql.cc | 7 +++++--
 src/lua/pg.cc    | 7 +++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/lua/mysql.cc b/src/lua/mysql.cc
index 7e5cf87258..64c63bc021 100644
--- a/src/lua/mysql.cc
+++ b/src/lua/mysql.cc
@@ -380,9 +380,12 @@ lbox_net_mysql_connect(struct lua_State *L)
 	}
 
 	if (*mysql_error(mysql)) {
-		const char *estr = mysql_error(mysql);
+		luaL_Buffer b;
+		luaL_buffinit(L, &b);
+		luaL_addstring(&b, mysql_error(mysql));
+		luaL_pushresult(&b);
 		mysql_close(mysql);
-		luaL_error(L, "%s", estr);
+		lua_error(L);
 	}
 
 	lua_pushstring(L, "raw");
diff --git a/src/lua/pg.cc b/src/lua/pg.cc
index 86e2867897..940cf75b7c 100644
--- a/src/lua/pg.cc
+++ b/src/lua/pg.cc
@@ -396,9 +396,12 @@ lbox_net_pg_connect(struct lua_State *L)
 	lua_pop(L, 1);
 
 	if (PQstatus(conn) != CONNECTION_OK) {
-		const char *msg = PQerrorMessage(conn);
+		luaL_Buffer b;
+		luaL_buffinit(L, &b);
+		luaL_addstring(&b, PQerrorMessage(conn));
+		luaL_pushresult(&b);
 		PQfinish(conn);
-		luaL_error(L, "%s", msg);
+		lua_error(L);
 	}
 
 	lua_pushstring(L, "raw");
-- 
GitLab