title: valgrind gives invalid read of size 1
body: <p>I have gone through several similarly asked questions regarding the same error code, most concern with passing invalid pointer addresses in return. However, this looks not to be the case here as my program correctly works with whatever address is passed in return. </p>
  
  <p><strong>format_string:</strong></p>
  
  <pre><code>static char *format_string(char *string)
  {
      int i;
  
      if (string == NULL) {
          return string;
      }
      string[0] = (char)toupper((int)string[0]);
  
      111-&gt;for (i = 1; string[i] != '\0'; i++) {
          if (!isalpha(string[i-1])) {
              string[i] = (char)toupper((int)string[i]);
          } else {
              string[i] = (char)tolower((int)string[i]);
          }
          if (string[i] == '/' || string[i] == '\\') {
          string[i] = ' ';
          }
      }
      /* Remove End of string White Spaces */
      while (string[--i]==' '); string[++i]='\0';
  
      return string;
  }
  </code></pre>
  
  <p><strong>metadata_extract:</strong></p>
  
  <pre><code>static int metadata_extract(const char *filename, struct kw_metadata *s)
  {
      char *memchar = NULL;
      s-&gt;obj = NULL;
      s-&gt;do_cleanup = &amp;do_on_cleanup;
      if (!is_of_type(filename)) {        
          return KW_ERROR;
      }
  
      TagLib_File* file = taglib_file_new(filename); 
      TagLib_Tag* tag = taglib_file_tag(file);
  
      s-&gt;type = strdup("Audio");
      s-&gt;tagc = 4;
      s-&gt;tagtype = (char **)malloc(4 * sizeof(char *));
      s-&gt;tagv = (char **)malloc(4 * sizeof(char *));
  
      memchar = strdup("title");
      s-&gt;tagtype[0] = memchar;
      memchar = strdup("artist");
      s-&gt;tagtype[1] = memchar;
      memchar = strdup("album");
      s-&gt;tagtype[2] = memchar;
      memchar = strdup("genre");
      s-&gt;tagtype[3] = memchar;
  
      153-&gt;memchar = strdup(taglib_tag_title(tag));
      memchar = format_string(memchar);
      s-&gt;tagv[0] = memchar;
      memchar = strdup(taglib_tag_artist(tag));
      memchar  = format_string(memchar);
      s-&gt;tagv[1] = memchar;
      memchar = strdup(taglib_tag_album(tag));
      160-&gt;memchar = format_string(memchar);
      s-&gt;tagv[2] = memchar;
      memchar = strdup(taglib_tag_genre(tag));
      memchar = format_string(memchar);
      s-&gt;tagv[3] = memchar;
  
      s-&gt;obj = file;
      s-&gt;do_init = &amp;do_on_init;
      s-&gt;do_cleanup = &amp;do_on_cleanup;
  
      taglib_tag_free_strings();
      taglib_file_free(file);
  
      return KW_SUCCESS;
  }
  </code></pre>
  
  <p><strong>valgrind:</strong></p>
  
  <pre><code>==16769== Invalid read of size 1
  ==16769==    at 0x5317605: format_string (plugin_taglib.c:111)
  ==16769==    by 0x531781F: metadata_extract (plugin_taglib.c:160)
  ==16769==    by 0x405EB3: metadata_extract (metadata_extract.c:36)
  ==16769==    by 0x403351: add_metadata_file (dbbasic.c:221)
  ==16769==    by 0x4032D5: add_file (dbbasic.c:174)
  ==16769==    by 0x406485: import_semantics (import.c:97)
  ==16769==    by 0x406440: import_semantics (import.c:92)
  ==16769==    by 0x4065AC: import (import.c:127)
  ==16769==    by 0x401916: main (kwest_main.c:87)
  ==16769==  Address 0x6f4ce11 is 0 bytes after a block of size 1 alloc'd
  ==16769==    at 0x4C2B3F8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==16769==    by 0x57A6D71: strdup (strdup.c:43)
  ==16769==    by 0x531780F: metadata_extract (plugin_taglib.c:159)
  ==16769==    by 0x405EB3: metadata_extract (metadata_extract.c:36)
  ==16769==    by 0x403351: add_metadata_file (dbbasic.c:221)
  ==16769==    by 0x4032D5: add_file (dbbasic.c:174)
  ==16769==    by 0x406485: import_semantics (import.c:97)
  ==16769==    by 0x406440: import_semantics (import.c:92)
  ==16769==    by 0x4065AC: import (import.c:127)
  ==16769==    by 0x401916: main (kwest_main.c:87)
  </code></pre>