forked from github/server
CID 26260: Resource leaks (RESOURCE_LEAK)
This commit is contained in:
parent
db6e9444d6
commit
59069ae342
1 changed files with 18 additions and 19 deletions
|
@ -33,30 +33,29 @@ 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')) {
|
||||||
|
fread(&data->version, sizeof(int), 1, F);
|
||||||
|
fseek(F, sizeof(int), SEEK_CUR);
|
||||||
|
}
|
||||||
|
else if (strchr(type, 'w')) {
|
||||||
|
int n = STREAM_VERSION;
|
||||||
|
data->version = RELEASE_VERSION;
|
||||||
|
fwrite(&data->version, sizeof(int), 1, F);
|
||||||
|
fwrite(&n, sizeof(int), 1, F);
|
||||||
|
}
|
||||||
|
fstream_init(&data->strm, F);
|
||||||
|
binstore_init(store, &data->strm);
|
||||||
|
tolua_pushusertype(L, (void *)data, TOLUA_CAST "storage");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
if (strchr(type, 'r')) {
|
return 0;
|
||||||
fread(&data->version, sizeof(int), 1, F);
|
|
||||||
fseek(F, sizeof(int), SEEK_CUR);
|
|
||||||
}
|
|
||||||
else if (strchr(type, 'w')) {
|
|
||||||
int n = STREAM_VERSION;
|
|
||||||
data->version = RELEASE_VERSION;
|
|
||||||
fwrite(&data->version, sizeof(int), 1, F);
|
|
||||||
fwrite(&n, sizeof(int), 1, F);
|
|
||||||
}
|
|
||||||
fstream_init(&data->strm, F);
|
|
||||||
binstore_init(store, &data->strm);
|
|
||||||
tolua_pushusertype(L, (void *)data, TOLUA_CAST "storage");
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_storage_read_unit(lua_State * L)
|
static int tolua_storage_read_unit(lua_State * L)
|
||||||
|
|
Loading…
Reference in a new issue