Memory leak in librosie.c#bootstrap
Created by: mohsinbeg
Reading the librosie.c code, I think we have a memory leak by not free-ing "name" variable. I've added a fix but since I am not a C expert, I am not sure.
static int bootstrap (lua_State *L, struct rosieL_string *rosie_home) {
const char *bootscript = "/src/core/bootstrap.lua";
LOG("About to bootstrap\n");
char *name = malloc(rosie_home->len + strlen(bootscript) + 1);
memcpy(name, rosie_home->ptr, rosie_home->len);
memcpy(name+(rosie_home->len), bootscript, strlen(bootscript)+1); /* +1 copies the NULL terminator */
int status = luaL_loadfile(L, name);
if (status != LUA_OK) {
free(name); // new code
return status;
}
status = lua_pcall(L, 0, LUA_MULTRET, 0);
free(name); // new code
return status;
}