Cleanup leaking memory and filehandles

This commit is contained in:
Moshe Kaplan 2014-07-30 22:52:34 -04:00
parent e726f82344
commit d555656a41
1 changed files with 6 additions and 0 deletions

View File

@ -220,6 +220,7 @@ int _isoReadZtable(isoFile *iso) {
size = (int)_tellfile(handle); size = (int)_tellfile(handle);
iso->Ztable = (char*)malloc(size); iso->Ztable = (char*)malloc(size);
if (iso->Ztable == NULL) { if (iso->Ztable == NULL) {
_closefile(handle);
return -1; return -1;
} }
@ -251,6 +252,7 @@ int _isoReadZ2table(isoFile *iso) {
size = (int)_tellfile(handle); size = (int)_tellfile(handle);
Ztable = (u32*)malloc(size); Ztable = (u32*)malloc(size);
if (Ztable == NULL) { if (Ztable == NULL) {
_closefile(handle);
return -1; return -1;
} }
@ -260,6 +262,7 @@ int _isoReadZ2table(isoFile *iso) {
iso->Ztable = (char*)malloc(iso->blocks*8); iso->Ztable = (char*)malloc(iso->blocks*8);
if (iso->Ztable == NULL) { if (iso->Ztable == NULL) {
free(Ztable);
return -1; return -1;
} }
@ -390,6 +393,7 @@ isoFile *isoOpen(const char *filename) {
iso->handle = _openfile(iso->filename, O_RDONLY); iso->handle = _openfile(iso->filename, O_RDONLY);
if (iso->handle == NULL) { if (iso->handle == NULL) {
printf("Error loading %s\n", iso->filename); printf("Error loading %s\n", iso->filename);
free(iso);
return NULL; return NULL;
} }
@ -459,6 +463,7 @@ isoFile *isoCreate(const char *filename, int flags) {
sprintf(Zfile, "%s.table", iso->filename); sprintf(Zfile, "%s.table", iso->filename);
iso->htable = _openfile(Zfile, O_WRONLY); iso->htable = _openfile(Zfile, O_WRONLY);
if (iso->htable == NULL) { if (iso->htable == NULL) {
free(iso);
return NULL; return NULL;
} }
} }
@ -466,6 +471,7 @@ isoFile *isoCreate(const char *filename, int flags) {
iso->handle = _openfile(iso->filename, O_WRONLY); iso->handle = _openfile(iso->filename, O_WRONLY);
if (iso->handle == NULL) { if (iso->handle == NULL) {
printf("Error loading %s\n", iso->filename); printf("Error loading %s\n", iso->filename);
free(iso);
return NULL; return NULL;
} }
printf("isoCreate: %s ok\n", iso->filename); printf("isoCreate: %s ok\n", iso->filename);