Fix Element::Identifier assignment leak (closes #205)
I didn't use 'fixes' because this doesn't strictly fix that specific bug (I think?). Anyway, it does remove strdup which is mentioned in the issue. Also fix elem.free not allowing DEFAULTFOO_PT_STUFF and similar to be freed.
This commit is contained in:
parent
1b2a52501d
commit
59afaec70f
40
src/Misc.cpp
40
src/Misc.cpp
@ -36,46 +36,6 @@ float restrict_flt(float f, float min, float max) //TODO Inline or macro or some
|
||||
return f;
|
||||
}
|
||||
|
||||
char *mystrdup(const char *s)
|
||||
{
|
||||
char *x;
|
||||
if (s)
|
||||
{
|
||||
x = (char*)malloc(strlen(s)+1);
|
||||
strcpy(x, s);
|
||||
return x;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void strlist_add(struct strlist **list, char *str)
|
||||
{
|
||||
struct strlist *item = (struct strlist*)malloc(sizeof(struct strlist));
|
||||
item->str = mystrdup(str);
|
||||
item->next = *list;
|
||||
*list = item;
|
||||
}
|
||||
|
||||
int strlist_find(struct strlist **list, char *str)
|
||||
{
|
||||
struct strlist *item;
|
||||
for (item=*list; item; item=item->next)
|
||||
if (!strcmp(item->str, str))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void strlist_free(struct strlist **list)
|
||||
{
|
||||
struct strlist *item;
|
||||
while (*list)
|
||||
{
|
||||
item = *list;
|
||||
*list = (*list)->next;
|
||||
free(item);
|
||||
}
|
||||
}
|
||||
|
||||
const static char hex[] = "0123456789ABCDEF";
|
||||
void strcaturl(char *dst, char *src)
|
||||
{
|
||||
|
14
src/Misc.h
14
src/Misc.h
@ -18,20 +18,6 @@ unsigned clamp_flt(float f, float min, float max);
|
||||
|
||||
float restrict_flt(float f, float min, float max);
|
||||
|
||||
char *mystrdup(const char *s);
|
||||
|
||||
struct strlist
|
||||
{
|
||||
char *str;
|
||||
struct strlist *next;
|
||||
};
|
||||
|
||||
void strlist_add(struct strlist **list, char *str);
|
||||
|
||||
int strlist_find(struct strlist **list, char *str);
|
||||
|
||||
void strlist_free(struct strlist **list);
|
||||
|
||||
void save_presets(int do_update);
|
||||
|
||||
void load_presets(void);
|
||||
|
@ -2632,9 +2632,6 @@ int LuaScriptInterface::elements_allocate(lua_State * l)
|
||||
if (!luacon_sim->elements[i].Enabled)
|
||||
{
|
||||
newID = i;
|
||||
luacon_sim->elements[i] = Element();
|
||||
luacon_sim->elements[i].Enabled = true;
|
||||
luacon_sim->elements[i].Identifier = mystrdup(identifier.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2646,9 +2643,6 @@ int LuaScriptInterface::elements_allocate(lua_State * l)
|
||||
if (!luacon_sim->elements[i].Enabled)
|
||||
{
|
||||
newID = i;
|
||||
luacon_sim->elements[i] = Element();
|
||||
luacon_sim->elements[i].Enabled = true;
|
||||
luacon_sim->elements[i].Identifier = mystrdup(identifier.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2656,6 +2650,10 @@ int LuaScriptInterface::elements_allocate(lua_State * l)
|
||||
|
||||
if (newID != -1)
|
||||
{
|
||||
luacon_sim->elements[newID] = Element();
|
||||
luacon_sim->elements[newID].Enabled = true;
|
||||
luacon_sim->elements[newID].Identifier = identifier;
|
||||
|
||||
lua_getglobal(l, "elements");
|
||||
lua_pushinteger(l, newID);
|
||||
lua_setfield(l, -2, identifier.c_str());
|
||||
@ -2876,7 +2874,7 @@ int LuaScriptInterface::elements_free(lua_State * l)
|
||||
return luaL_error(l, "Invalid element");
|
||||
|
||||
ByteString identifier = luacon_sim->elements[id].Identifier;
|
||||
if(identifier.BeginsWith("DEFAULT"))
|
||||
if(identifier.BeginsWith("DEFAULT_PT_"))
|
||||
return luaL_error(l, "Cannot free default elements");
|
||||
|
||||
luacon_sim->elements[id].Enabled = false;
|
||||
|
Loading…
Reference in New Issue
Block a user