mirror of
https://github.com/pspdev/pspsdk.git
synced 2025-10-04 17:09:09 +00:00
Merge pull request #84 from ryancaicse/master
Fix resource leaks in different places
This commit is contained in:
@@ -362,17 +362,20 @@ int main(int argc, char *argv[])
|
|||||||
buffer = malloc(size);
|
buffer = malloc(size);
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
printf("Failed to allocate memory.\n");
|
printf("Failed to allocate memory.\n");
|
||||||
|
fclose(dest);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fread(buffer, 1, size, source) != size) {
|
if (fread(buffer, 1, size, source) != size) {
|
||||||
printf("Failed to read file.\n");
|
printf("Failed to read file.\n");
|
||||||
|
fclose(dest);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
fclose(source);
|
fclose(source);
|
||||||
|
|
||||||
if (!(dest = fopen(f_dest, "wb+"))) {
|
if (!(dest = fopen(f_dest, "wb+"))) {
|
||||||
printf("Failed to open/create %s.\n", f_dest);
|
printf("Failed to open/create %s.\n", f_dest);
|
||||||
|
fclose(dest);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -40,11 +40,13 @@ int main(int argc, char *argv[])
|
|||||||
buffer = malloc(fd_size);
|
buffer = malloc(fd_size);
|
||||||
if(buffer == NULL) {
|
if(buffer == NULL) {
|
||||||
printf("Failed to allocate memory.\n");
|
printf("Failed to allocate memory.\n");
|
||||||
|
fclose(source);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fread(buffer,1,fd_size,source) != fd_size) {
|
if(fread(buffer,1,fd_size,source) != fd_size) {
|
||||||
printf("Failed to read file.\n");
|
printf("Failed to read file.\n");
|
||||||
|
fclose(source);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
fclose(source);
|
fclose(source);
|
||||||
|
@@ -183,6 +183,7 @@ unsigned char *load_file(const char *file, unsigned int *size)
|
|||||||
if(*size < sizeof(Elf32_Ehdr))
|
if(*size < sizeof(Elf32_Ehdr))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error, invalid file size\n");
|
fprintf(stderr, "Error, invalid file size\n");
|
||||||
|
fclose(fp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,6 +191,7 @@ unsigned char *load_file(const char *file, unsigned int *size)
|
|||||||
if(data == NULL)
|
if(data == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error, could not allocate memory for ELF\n");
|
fprintf(stderr, "Error, could not allocate memory for ELF\n");
|
||||||
|
fclose(fp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -132,6 +132,7 @@ unsigned char *load_file(const char *file)
|
|||||||
if(size < sizeof(Elf32_Ehdr))
|
if(size < sizeof(Elf32_Ehdr))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error, invalid file size\n");
|
fprintf(stderr, "Error, invalid file size\n");
|
||||||
|
fclose(fp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +140,7 @@ unsigned char *load_file(const char *file)
|
|||||||
if(data == NULL)
|
if(data == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error, could not allocate memory for ELF\n");
|
fprintf(stderr, "Error, could not allocate memory for ELF\n");
|
||||||
|
fclose(fp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user