1. Wez Furlong
  2. atomicparsley

Commits

Wez Furlong  committed 4caecca

some memory leak fixups from Edriss Mirzadeh

  • Participants
  • Parent commits 8aa520c
  • Branches default

Comments (0)

Files changed (3)

File src/main.cpp

View file
  • Ignore whitespace
 "                                      If possible, padding will be used to update without a full rewrite.\n"
 "\n"
 #if defined (WIN32)
-"  --preserveTime                      Will overwrite the original file in place (--overWrite forcrd),\n"
+"  --preserveTime                      Will overwrite the original file in place (--overWrite forced),\n"
 "                                      but will also keep the original file's timestamps intact.\n"
 "\n"
 #endif
 
 int wmain( int argc, wchar_t *arguments[])
 {
+	int return_val=0;
 	uint16_t name_len = wcslen(arguments[0]);
 	if (wmemcmp(arguments[0] + (name_len-9), L"-utf8.exe", 9) == 0 ||
 			wmemcmp(arguments[0] + (name_len-9), L"-UTF8.exe", 9) == 0) {
 			strip_bogusUTF16toRawUTF8((unsigned char*) argv[z], 8*wchar_length, arguments[z], wchar_length );
 		}
 	}
+
 	argv[argc] = NULL;
 
-	return real_main(argc, argv);
+	return_val = real_main(argc, argv);
+
+	for (int free_cnt=0; free_cnt<argc; free_cnt++) {
+		free(argv[free_cnt]);
+		argv[free_cnt]=NULL;
+	}
+
+	free(argv);
+	argv=NULL;
+
+	return return_val;
 }
 
 #else

File src/parsley.cpp

View file
  • Ignore whitespace
 
 void APar_FreeMemory() {
 	for(int iter=0; iter < atom_number; iter++) {
+		if (parsedAtoms[iter].AtomicName != NULL) {
+				free(parsedAtoms[iter].AtomicName);
+				parsedAtoms[iter].AtomicName=NULL;
+			}
 		if (parsedAtoms[iter].AtomicData != NULL) {
 			free(parsedAtoms[iter].AtomicData);
 			parsedAtoms[iter].AtomicData = NULL;

File src/util.cpp

View file
  • Ignore whitespace
 		
 		aFile = _wfopen(utf16_filepath, Lfile_flags);
 		
+		free(Lfile_flags); Lfile_flags=NULL;
 		free(utf16_filepath);
 		utf16_filepath = NULL;
 #endif
 }
 
 wchar_t* Convert_multibyteUTF8_to_wchar(const char* input_utf8) { //TODO: is this like mbstowcs?
+	wchar_t *return_val=NULL;
 	size_t string_length = strlen(input_utf8) + 1;  //account for terminating NULL
 	size_t char_glyphs = mbstowcs(NULL, input_utf8, string_length); //passing NULL pre-calculates the size of wchar_t needed
 			
 	memset(utf16_conversion, 0, string_length * 2 );
 			
 	int utf_16_glyphs = UTF8ToUTF16BE(utf16_conversion, char_glyphs * 2, (unsigned char*)input_utf8, string_length);
-	return Convert_multibyteUTF16_to_wchar((char*)utf16_conversion, (size_t)utf_16_glyphs, false );
+	return_val = Convert_multibyteUTF16_to_wchar((char*)utf16_conversion, (size_t)utf_16_glyphs, false );
+	free(utf16_conversion); utf16_conversion=NULL;
+	return (return_val);
 }
 
 //these flags from id3v2 2.4