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

View file

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