Author: gschneider
Date: Fri Oct 9 23:02:44 2009
New Revision: 43347
URL:
http://svn.reactos.org/svn/reactos?rev=43347&view=rev
Log:
- 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.
Modified:
trunk/reactos/base/applications/downloader/xml.c
trunk/reactos/base/services/dhcp/memory.c
trunk/reactos/boot/freeldr/tools/deptool.c
trunk/reactos/tools/buildno/buildno.cpp
trunk/reactos/tools/cdmake/cdmake.c
trunk/reactos/tools/mkconfig.c
trunk/reactos/tools/rbuild/rbuild.h
trunk/reactos/tools/stubgen.c
Modified: trunk/reactos/base/applications/downloader/xml.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/download…
==============================================================================
--- trunk/reactos/base/applications/downloader/xml.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/downloader/xml.c [iso-8859-1] Fri Oct 9 23:02:44
2009
@@ -203,6 +203,7 @@
if(!XML_Parse(parser, buffer, len, done))
{
MessageBoxW(0,Strings[IDS_XMLERROR_2],0,0);
+ fclose(file);
return FALSE;
}
}
Modified: trunk/reactos/base/services/dhcp/memory.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/dhcp/memory.…
==============================================================================
--- trunk/reactos/base/services/dhcp/memory.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/dhcp/memory.c [iso-8859-1] Fri Oct 9 23:02:44 2009
@@ -829,7 +829,11 @@
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);
Modified: trunk/reactos/boot/freeldr/tools/deptool.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/tools/deptool…
==============================================================================
--- trunk/reactos/boot/freeldr/tools/deptool.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/tools/deptool.c [iso-8859-1] Fri Oct 9 23:02:44 2009
@@ -50,6 +50,10 @@
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 @@
if (ferror(DependFile))
{
printf("deptool: Dependency file read error.\n");
+ free(DependFileData);
+ free(NewDependFileData);
fclose(DependFile);
return ERROR_READERROR;
}
@@ -121,9 +127,13 @@
{
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;
}
Modified: trunk/reactos/tools/buildno/buildno.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/buildno/buildno.cpp?…
==============================================================================
--- trunk/reactos/tools/buildno/buildno.cpp [iso-8859-1] (original)
+++ trunk/reactos/tools/buildno/buildno.cpp [iso-8859-1] Fri Oct 9 23:02:44 2009
@@ -236,14 +236,22 @@
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 @@
return;
}
fwrite(s1, 1, strlen(s1), h);
- fclose (h);
+ fclose(h);
}
void
Modified: trunk/reactos/tools/cdmake/cdmake.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/cdmake/cdmake.c?rev=…
==============================================================================
--- trunk/reactos/tools/cdmake/cdmake.c [iso-8859-1] (original)
+++ trunk/reactos/tools/cdmake/cdmake.c [iso-8859-1] Fri Oct 9 23:02:44 2009
@@ -1259,7 +1259,10 @@
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)
{
Modified: trunk/reactos/tools/mkconfig.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkconfig.c?rev=43347…
==============================================================================
--- trunk/reactos/tools/mkconfig.c [iso-8859-1] (original)
+++ trunk/reactos/tools/mkconfig.c [iso-8859-1] Fri Oct 9 23:02:44 2009
@@ -44,15 +44,18 @@
{
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)
{
Modified: trunk/reactos/tools/rbuild/rbuild.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/rbuild/rbuild.h?rev=…
==============================================================================
--- trunk/reactos/tools/rbuild/rbuild.h [iso-8859-1] (original)
+++ trunk/reactos/tools/rbuild/rbuild.h [iso-8859-1] Fri Oct 9 23:02:44 2009
@@ -455,6 +455,7 @@
void ParseToolsets ( const Project& project, const XMLElement& node );
public:
+ virtual ~ToolsetDirective() { }
bool IsEnabled () const;
};
@@ -469,6 +470,7 @@
public:
CompilerDirective (): enabled ( true ) { }
+ virtual ~CompilerDirective() { }
void SetCompiler ( CompilerType compiler );
void UnsetCompiler ( CompilerType compiler );
void SetAllCompilers ();
Modified: trunk/reactos/tools/stubgen.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/stubgen.c?rev=43347&…
==============================================================================
--- trunk/reactos/tools/stubgen.c [iso-8859-1] (original)
+++ trunk/reactos/tools/stubgen.c [iso-8859-1] Fri Oct 9 23:02:44 2009
@@ -88,7 +88,13 @@
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 @@
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 @@
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 @@
}
fclose( out );
-
+ pclose( make_f );
return 0;
}