Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit e747aec

Browse files
committed
Lua: Fix possible memory leak in lua_port_open()
This patch fixes #11, in which Tieske has reported, that in case luaL_checkstring() fails, there would still remain struct rs232_port_t allocated, thus possibly producing unwanted memory leak. Signed-off-by: Petr Štetiar <[email protected]>
1 parent b3ce3bf commit e747aec

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

bindings/lua/luars232.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ static int lua_port_open(lua_State *L)
105105
int ret = 0;
106106
struct rs232_port_t *p = NULL;
107107
struct rs232_port_t **ud = NULL;
108+
const char *dev = luaL_checkstring(L, 1);
108109

109110
p = rs232_init();
110111
if (p == NULL) {
@@ -115,7 +116,7 @@ static int lua_port_open(lua_State *L)
115116

116117
DBG("p=%p \n", (void *)p);
117118

118-
rs232_set_device(p, (char *) luaL_checkstring(L, 1));
119+
rs232_set_device(p, dev);
119120
ret = rs232_open(p);
120121
if (ret > RS232_ERR_NOERROR) {
121122
free(p->pt);

0 commit comments

Comments
 (0)