CID 26260: Resource leaks (RESOURCE_LEAK)

This commit is contained in:
Enno Rehling 2015-10-29 16:28:59 +01:00
parent db6e9444d6
commit 59069ae342
1 changed files with 18 additions and 19 deletions

View File

@ -33,16 +33,13 @@ static int tolua_storage_create(lua_State * L)
{
const char *filename = tolua_tostring(L, 1, 0);
const char *type = tolua_tostring(L, 2, "rb");
gamedata *data = (gamedata *)calloc(1, sizeof(gamedata));
storage *store = (storage *)calloc(1, sizeof(storage));
FILE * F;
data->store = store;
F = fopen(filename, type);
if (!F) {
return 0;
}
gamedata *data = (gamedata *)calloc(1, sizeof(gamedata));
storage *store = (storage *)calloc(1, sizeof(storage));
data->store = store;
if (strchr(type, 'r')) {
fread(&data->version, sizeof(int), 1, F);
fseek(F, sizeof(int), SEEK_CUR);
@ -58,6 +55,8 @@ static int tolua_storage_create(lua_State * L)
tolua_pushusertype(L, (void *)data, TOLUA_CAST "storage");
return 1;
}
return 0;
}
static int tolua_storage_read_unit(lua_State * L)
{