- Various resource fixes (unclosed files, unchecked memory allocations, missing destructor, not freed memory)

- Patch by Russell with some modifications by myself
See issue #4662 for more details.

svn path=/trunk/; revision=43347
This commit is contained in:
Gregor Schneider 2009-10-09 21:02:44 +00:00
parent ef0f96e223
commit ce47d4b62f
8 changed files with 49 additions and 5 deletions

View file

@ -203,6 +203,7 @@ BOOL ProcessXML (const char* filename, struct Category* Root)
if(!XML_Parse(parser, buffer, len, done))
{
MessageBoxW(0,Strings[IDS_XMLERROR_2],0,0);
fclose(file);
return FALSE;
}
}

View file

@ -829,7 +829,11 @@ struct class *add_class (type, name)
user_class_hash = new_hash ();
if (!tname || !class || !vendor_class_hash || !user_class_hash)
{
if (tname != NULL)
free(tname);
return (struct class *)0;
}
memset (class, 0, sizeof *class);
strcpy (tname, name);

View file

@ -50,6 +50,10 @@ int main(int argc, char *argv[])
if (!DependFileData || !NewDependFileData)
{
printf("deptool: Out of memory!\n");
if (DependFileData != NULL)
free(DependFileData);
if (NewDependFileData != NULL)
free(NewDependFileData);
fclose(DependFile);
return ERROR_OUTOFMEMORY;
}
@ -61,6 +65,8 @@ int main(int argc, char *argv[])
if (ferror(DependFile))
{
printf("deptool: Dependency file read error.\n");
free(DependFileData);
free(NewDependFileData);
fclose(DependFile);
return ERROR_READERROR;
}
@ -121,9 +127,13 @@ int main(int argc, char *argv[])
{
printf("deptool: Dependency file write error.\n");
fclose(DependFile);
free(DependFileData);
free(NewDependFileData);
return ERROR_WRITEERROR;
}
fclose(DependFile);
free(DependFileData);
free(NewDependFileData);
return ERROR_SUCCESS;
}

View file

@ -236,14 +236,22 @@ write_h (int build, char *buildstr, long revno)
char* orig;
orig = (char *) malloc(length);
if (orig == NULL)
{
fclose(h);
free(s1);
return;
}
fseek(h, 0, SEEK_SET);
fread(orig, 1, length, h);
if (memcmp(s1, orig, length) == 0)
{
fclose(h);
free(s1);
free(orig);
return;
}
free(orig);
}
fclose(h);
}
@ -259,7 +267,7 @@ write_h (int build, char *buildstr, long revno)
return;
}
fwrite(s1, 1, strlen(s1), h);
fclose (h);
fclose(h);
}
void

View file

@ -1259,7 +1259,10 @@ static void pass(void)
size = ftell(file);
fseek(file, 0, SEEK_SET);
if (size == 0 || (size % 2048))
{
fclose(file);
error_exit("Invalid boot image size (%lu bytes)\n", size);
}
boot_image_size = size / 512;
while (size > 0)
{

View file

@ -44,15 +44,18 @@ write_if_change(char* outbuf, char* filename)
{
fprintf(stderr, "Failed to read data\n");
fclose(out);
free(cmpbuf);
return(1);
}
if (end == strlen(outbuf) && memcmp(cmpbuf, outbuf, end) == 0)
{
fclose(out);
free(cmpbuf);
return(0);
}
fclose(out);
free(cmpbuf);
out = fopen(filename, "wb");
if (out == NULL)
{

View file

@ -455,6 +455,7 @@ protected:
void ParseToolsets ( const Project& project, const XMLElement& node );
public:
virtual ~ToolsetDirective() { }
bool IsEnabled () const;
};
@ -469,6 +470,7 @@ protected:
public:
CompilerDirective (): enabled ( true ) { }
virtual ~CompilerDirective() { }
void SetCompiler ( CompilerType compiler );
void UnsetCompiler ( CompilerType compiler );
void SetAllCompilers ();

View file

@ -88,7 +88,13 @@ int main( int argc, char **argv ) {
if( new_f ) continue;
new_f = (stub *)malloc( sizeof(stub) );
if( !new_f ) {fprintf( stderr, "Out of memory\n" ); return 1;}
if( !new_f )
{
fprintf( stderr, "Out of memory\n" );
fclose( out );
pclose( make_f );
return 1;
}
new_f->name = strdup( line );
new_f->next = functions;
@ -129,7 +135,14 @@ int main( int argc, char **argv ) {
if( new_f ) continue;
new_f = (stub *)malloc( sizeof(stub) );
if( !new_f ) {fprintf( stderr, "Out of memory\n" ); return 1;}
if( !new_f )
{
fprintf( stderr, "Out of memory\n" );
fclose( out );
pclose( make_f );
pclose( nm_f );
return 1;
}
new_f->name = strdup( import_sign + 1 );
new_f->origin = origin;
@ -137,7 +150,7 @@ int main( int argc, char **argv ) {
imports = new_f;
}
fclose( nm_f );
pclose( nm_f );
}
/* Now we have a list of unique functions and a list of imports,
@ -152,6 +165,6 @@ int main( int argc, char **argv ) {
}
fclose( out );
pclose( make_f );
return 0;
}