Random crashes on simulator and device

I added a file I/O system in my game to load database stuff. It worked fine but I noticed these warnings on the console:

objc[3341]: Object 0x7716e50 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[3341]: Object 0x77172a0 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[3341]: Object 0x7716d10 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[3341]: Object 0x77198c0 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[3341]: Object 0x7719b60 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[3341]: Object 0x8106610 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
Cocos2d: cocos2d: cocos2d-2.0-rc2-x-2.0.1
objc[3341]: Object 0x81084c0 of class __NSCFData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[3341]: Object 0x81086e0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[3341]: Object 0x8108700 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[3341]: Object 0x8108730 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[3341]: Object 0x81085b0 of class __NSCFData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[3341]: Object 0x81085f0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[3341]: Object 0x8108760 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[3341]: Object 0x8108610 of class NSPathStore2 autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[3341]: Object 0x81087b0 of class __NSCFData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug

I ignored them because the game ran smoothly but after several tests, the game started to randomly crash at the start, throwing a SIGABRT error. The weird thing is, sometimes it crashes, sometimes it doesn’t.
My File I/O is like this:

// FileReader.h
#include "cocos2d.h"

using namespace std;
using namespace cocos2d;

class FileReader {
private:
   vector< string > mFileContents;

public:
   FileReader( string pFileName, char pMode = 'r' );
};

// FileReader.cpp
#include "FileReader.h"
#include 
#include "cocos2d.h"

using namespace cocos2d;
using namespace std;

FileReader::FileReader( string pFileName, char pMode ) {
   // Initialize variables needed
   unsigned long fileSize = 0;
   unsigned char * fileContents = NULL;
   string thisLine, result, fullPath, contents;

   // Get absolute path of file
   fullPath = CCFileUtils::sharedFileUtils( ) -> fullPathFromRelativePath( pFileName.c_str( ) );

   // Get data of file
   fileContents = CCFileUtils::sharedFileUtils( ) -> getFileData( fullPath.c_str( ) , "r", &fileSize );
   contents.append( ( char * ) fileContents );

   // Create a string stream so that we can use getline( ) on it
   istringstream fileStringStream( contents );

   // Get file contents line by line
   while ( getline( fileStringStream, thisLine ) ) {
      // Put all lines in vector
      mFileContents.push_back( thisLine );
   }

   // After this, mFileContents will have an extra entry and will have the value '\x04'.
   // We should remove this by popping it out the vector.
   mFileContents.pop_back( );

   // Delete buffer created by fileContents. This part is required.
   if ( fileContents ) {
      delete[ ] fileContents;
      fileContents = NULL;
   }

   // For testing purposes
   cout << "[ NOTICE ] Finished opening file: " << pFileName.c_str( ) << endl;
}

Any help?

No one?

fileContents = CCFileUtils::sharedFileUtils( ) -> getFileData( fullPath.c_str( ) , “r”, &fileSize );
contents.append( ( char * ) fileContents );

fileContents is not end with ‘’.

How do I end it with ‘’? Do I append it on the string ?

I think you can use this function
string& append ( const char * s, size_t n );

So I can use unsigned long fileSize for size_t n ?

Yeap.

It removed the random crash but it didn’t remove the large wall of warnings on the console.

Did you create new thread?

No. It’s on a different class. How do I implement threads on it?

It is not problem if only use one thread.
Because we create autorelease pool in main.cpp.

Could you paste a demo to reproduce it?
I have not seen this warnings before.
Thank you.

I’m not sure what caused it but when I added that class above, that’s when those warnings first appeared.

even i am getting the same issue, But in my code i am using pThread to create new thread, is there any way to fix the issue.