title: Out of memory when using sqlite3
body: <p>I am just beginning with programming in c++ (IDE is CodeBlocks).</p>
  
  <p>I wrote two simple classes (Song and Metadata) and testing around with sqlite.</p>
  
  <p>The Problem: My program seems to get insufficient memory: When I start the program it either crashes immediately or the sqlite3_open command returns the error "out of memory". When I test the SQLITE function without any other code, it works!</p>
  
  <p>So this does not work:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "metadata.h"
  #include "Song.h"
  #include &lt;cstdio&gt;
  #include "sqlite3.h"
  
  using namespace std;
  
  int main()
  {
      // Without this block it DOES work!
      Metadata* tmpMeta  = new Metadata("Eiffel 65", "Blue", "Europop");
      Song* tmpSong;
      tmpSong = new Song();
      tmpSong-&gt;set_metadata(*tmpMeta);
      // end of block
  
      sqlite3 *db;
      int rc;
      rc = sqlite3_open_v2("test.db", &amp;db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
      cout &lt;&lt; "Result: " &lt;&lt; sqlite3_errmsg(db) &lt;&lt; '\n';
      sqlite3_close(db);
      return 0;
  }
  </code></pre>
  
  <p>Please see the Song and Metadata classes attached.</p>
  
  <p>I do not know how to react to this error.</p>
  
  <p>My environment:
  - Windows 8, 64 bit
  - Code::Blocks 10.05
  - Compiler: GNU GCC Compiler</p>
  
  <p>Thank you in advance!</p>
  
  <p>Greetings
  Sebastian</p>
  
  <p>Song.h:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  #include "metadata.h"
  
  using namespace std;
  
  class Song {
      private:
      Metadata metadata;
      unsigned int iD;
      char filename[400];
  
      public:
      //Constructors
      Song( Metadata, unsigned int, const char*);
      Song( );
  
      //Methods
      void set_metadata(Metadata&amp; meta);
      void set_id(unsigned int i);
      void set_filename(const char* f);
  
      Metadata get_metadata();
      unsigned int get_id();
      const char* get_filename();
  
  };
  </code></pre>
  
  <p>Song.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Song.h"
  
  using namespace std;
  
  Song::Song(Metadata m, unsigned int id, const char* f) {
      metadata = m;
      iD = id;
      strncpy(filename, f, sizeof(filename)-1);
      filename[sizeof(filename)] = '\0';
  }
  
  Song::Song( ) {
      Metadata tmpMeta;
      metadata = tmpMeta;
  
      iD = 0;
      strncpy(filename, "unknown", sizeof(filename) -1);
      filename[sizeof(filename)] = '\0';
  }
  
  void Song::set_filename(const char* f) {
      strncpy( filename, f, sizeof(filename)-1 );
      filename[sizeof(filename)] = '\0';
  }
  
  void Song::set_id(unsigned int i) {
      iD = i;
  }
  
  void Song::set_metadata(Metadata&amp; meta) {
      metadata = meta;
  }
  
  Metadata Song::get_metadata() {
      return metadata;
  }
  
  const char* Song::get_filename() {
      return filename;
  }
  
  unsigned int Song::get_id() {
      return iD;
  }
  </code></pre>
  
  <p>Metadata.h:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  #ifndef _METADATA_H_
  #define _METADATA_H_
  
  using namespace std;
  class Metadata {
      private:
      unsigned int trackNumber;
      char artist[20];
      char title[20];
      unsigned int year;
      char genre[20];
      char album[20];
  
      public:
      Metadata(const char*, const char*, const char*);
  
      const char* get_artist();
      const char* get_title();
      const char* get_album();
      const char* get_genre();
      unsigned int get_trackNumber();
      unsigned int get_year();
  
      void set_artist(const char*);
      void set_title(const char*);
      void set_album(const char*);
      void set_genre(const char*);
      void set_year(unsigned int);
      void set_trackNumber(unsigned int);
  };
  
  #endif
  </code></pre>
  
  <p>Metadata.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "metadata.h"
  
  Metadata::Metadata(const char* ar, const char* tit, const char* al) {
      trackNumber = 0;
      year = 0;
      strncpy(genre, "unknown", sizeof(genre) -1);
      genre[sizeof(genre)] = '\0';
  
      strncpy(artist, ar, sizeof(artist) -1);
      artist[sizeof(artist)] = '\0';
  
      strncpy(title, tit, sizeof(title) -1);
      title[sizeof(title)] = '\0';
  
      strncpy(album, al, sizeof(album) -1);
      album[sizeof(album)] = '\0';
  }
  
  const char* Metadata::get_artist() {
      return artist;
  }
  
  const char* Metadata::get_title() {
      return title;
  }
  
  const char* Metadata::get_album() {
      return album;
  }
  
  const char* Metadata::get_genre() {
      return genre;
  }
  
  void Metadata::set_artist(const char* ar) {
      strncpy(artist, ar, sizeof(artist) -1);
      artist[sizeof(artist)] = '\0';
  }
  
  void Metadata::set_title(const char* tit) {
      strncpy(title, tit, sizeof(title) -1);
      title[sizeof(title)] = '\0';
  }
  
  void Metadata::set_album(const char* al) {
      strncpy(album, al, sizeof(album) -1);
      album[sizeof(album)] = '\0';
  }
  
  void Metadata::set_genre(const char* g) {
      strncpy(genre, g, sizeof(genre) -1);
      genre[sizeof(genre)] = '\0';
  }
  
  void Metadata::set_trackNumber(unsigned int tn) {
      trackNumber = tn;
  }
  
  void Metadata::set_year(unsigned int y) {
      year = y;
  }
  </code></pre>