I am currently working on a project for my school and I am having issues with my code. The purpose of the programm is to implement a plugin manager that search in a directory all "*_plugin.so" file and add a plugin descriptor into a simple linked list.
The C code :
      //struct of a single node
      typedef
      struct _chainon_ { 
        plugin_descriptor * desc;
        struct _chainon_ * next;
    } Chainon;
      // manager that contains sentry node & number of plugins contained by the list
      struct plugin_manager_t {
        int nbElts;  
        Chainon * sentinel;
    };
  typedef 
  struct {
    const char *    m_name;     // nom du filtre
    const char *    m_description;  // description de l'effet du filtre
    filter_function m_filtre;       // fonction de réalisation du filtre
  } plugin_descriptor;
Now the register_plugin function, it is called while the programm find a new plugin in the directory, it calls an init_ function that call register_plugin :
  void
  init_(plugin_manager * pm)
  {
    register_plugin(pm,
            "null_filter",
            "Exemple de filtre inutile",
            null_filter);
  }
and then it is supposed to add the new plug to the list :
  void
  register_plugin(plugin_manager * pm,
          const char filter_name[],
          const char filter_description[],
          filter_function the_filter)
  {
      Chainon * n = (Chainon *)malloc(sizeof(Chainon)); //new node that i want to add to the linked list
      n->desc = NULL;
      n->next = NULL;
      n->desc->m_name = filter_name;
      n->desc->m_description = filter_description;
      n->desc->m_filtre = the_filter;
      Chainon * current = pm->sentinel;
      for(int i=0;i<pm->nbElts;i++){
        current=current->next;
        i++;
      }
      current->next = n;
  }
And that is what I am getting with valgrind while I execute this programm :
> ==7022== Invalid write of size 8
> ==7022==    at 0x4015A7: register_plugin (pluginmanager.cc:165)
> ==7022==    by 0x66E1BDC: init_ (null_filter_plugin.cc:23)
> ==7022==    by 0x401483: discover_plugins (pluginmanager.cc:113)
> ==7022==    by 0x401187: main (main.cc:17)
> ==7022==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
> ==7022== 
> ==7022== 
> ==7022== Process terminating with default action of signal 11 (SIGSEGV)
> ==7022==  Access not within mapped region at address 0x0
> ==7022==    at 0x4015A7: register_plugin (pluginmanager.cc:165)
> ==7022==    by 0x66E1BDC: init_ (null_filter_plugin.cc:23)
> ==7022==    by 0x401483: discover_plugins (pluginmanager.cc:113)
> ==7022==    by 0x401187: main (main.cc:17)
> ==7022==  If you believe this happened as a result of a stack
> ==7022==  overflow in your program's main thread (unlikely but
> ==7022==  possible), you can try to increase the size of the
> ==7022==  main thread stack using the --main-stacksize= flag.
> ==7022==  The main thread stack size used in this run was 8388608.
I am novice at C programming
But I do not understand why I could not initialize "n->desc->name" since I allocated the memory with malloc and then initialized everything to NULL ?
Any help would be appreciate !
Thank you
 
     
    