Diff for /rpl/src/gestion_objets.c between versions 1.16 and 1.19

version 1.16, 2010/05/13 19:09:18 version 1.19, 2010/05/22 21:47:07
Line 877  liberation(struct_processus *s_etat_proc Line 877  liberation(struct_processus *s_etat_proc
         {          {
             if (decrementation_atomique(s_objet) > 0)              if (decrementation_atomique(s_objet) > 0)
             {              {
                   BUG((*(*((struct_fichier *) (*s_objet).objet)).format)
                           .nombre_occurrences <= 1,
                           pthread_mutex_unlock(&((*s_objet).mutex)),
                           printf("(*(*((struct_fichier *) (*s_objet).objet))"
                           ".format).nombre_occurrences=%ld\n",
                           (*(*((struct_fichier *) (*s_objet).objet)).format)
                           .nombre_occurrences));
   
                   liberation(s_etat_processus,
                           (*((struct_fichier *) (*s_objet).objet)).format);
                 return;                  return;
             }              }
   
             liberation(s_etat_processus,              liberation(s_etat_processus,
                     (*((struct_fichier *) (*s_objet).objet)).format);                      (*((struct_fichier *) (*s_objet).objet)).format);
   
             free((unsigned char *) (*((struct_fichier *)              free((unsigned char *) (*((struct_fichier *)
                     (*s_objet).objet)).nom);                      (*s_objet).objet)).nom);
             free((struct_fichier *) ((*s_objet).objet));              free((struct_fichier *) ((*s_objet).objet));
Line 1208  liberation(struct_processus *s_etat_proc Line 1217  liberation(struct_processus *s_etat_proc
         {          {
             if (decrementation_atomique(s_objet) > 0)              if (decrementation_atomique(s_objet) > 0)
             {              {
                   BUG((*(*((struct_socket *) (*s_objet).objet)).format)
                           .nombre_occurrences <= 1,
                           pthread_mutex_unlock(&((*s_objet).mutex)),
                           printf("(*(*((struct_socket *) (*s_objet).objet))"
                           ".format).nombre_occurrences=%ld\n",
                           (*(*((struct_socket *) (*s_objet).objet)).format)
                           .nombre_occurrences));
   
                   liberation(s_etat_processus, (*((struct_socket *)
                           (*s_objet).objet)).format);
                 return;                  return;
             }              }
   
             liberation(s_etat_processus, (*((struct_socket *)              liberation(s_etat_processus, (*((struct_socket *)
                     (*s_objet).objet)).format);                      (*s_objet).objet)).format);
   
             free((unsigned char *) (*((struct_socket *) (*s_objet).objet))              free((unsigned char *) (*((struct_socket *) (*s_objet).objet))
                     .adresse);                      .adresse);
             free((unsigned char *) (*((struct_socket *) (*s_objet).objet))              free((unsigned char *) (*((struct_socket *) (*s_objet).objet))
Line 1749  copie_objet(struct_processus *s_etat_pro Line 1769  copie_objet(struct_processus *s_etat_pro
             if (type == 'P')              if (type == 'P')
             {              {
                 incrementation_atomique(s_objet);                  incrementation_atomique(s_objet);
   
                   if (((*((struct_fichier *) ((*s_objet).objet))).format =
                           copie_objet(s_etat_processus, (*((struct_fichier *)
                           ((*s_objet).objet))).format, 'P')) == NULL)
                   {
                       return(NULL);
                   }
   
                 return(s_objet);                  return(s_objet);
             }              }
   
Line 2265  copie_objet(struct_processus *s_etat_pro Line 2293  copie_objet(struct_processus *s_etat_pro
             if (type == 'P')              if (type == 'P')
             {              {
                 incrementation_atomique(s_objet);                  incrementation_atomique(s_objet);
   
                   if (((*((struct_socket *) ((*s_objet).objet)))
                           .format = copie_objet(s_etat_processus,
                           (*((struct_socket *) ((*s_objet).objet))).format, 'P'))
                           == NULL)
                   {
                       return(NULL);
                   }
   
                 return(s_objet);                  return(s_objet);
             }              }
   
Line 3555  typedef struct memoire Line 3592  typedef struct memoire
     int                 profondeur;      int                 profondeur;
 #   endif  #   endif
     struct memoire      *suivant;      struct memoire      *suivant;
     pthread_t           thread;  
     pid_t               pid;  
 } struct_memoire;  } struct_memoire;
   
 static struct_memoire       *debug = NULL;  static struct_memoire       *debug = NULL;
Line 3564  static unsigned long long ordre = 0; Line 3599  static unsigned long long ordre = 0;
 static pthread_mutex_t      mutex_allocation = PTHREAD_MUTEX_INITIALIZER;  static pthread_mutex_t      mutex_allocation = PTHREAD_MUTEX_INITIALIZER;
   
 #define check(a, b) ((strcmp(#a, fonction) == 0) && (ligne == b))  #define check(a, b) ((strcmp(#a, fonction) == 0) && (ligne == b))
   #undef CORE_DUMP
   
 void *  void *
 debug_memoire_ajout(size_t taille, const unsigned char *fonction,  debug_memoire_ajout(size_t taille, const unsigned char *fonction,
Line 3591  debug_memoire_ajout(size_t taille, const Line 3627  debug_memoire_ajout(size_t taille, const
     (*debug).ligne = ligne;      (*debug).ligne = ligne;
     (*debug).taille = taille;      (*debug).taille = taille;
     (*debug).ordre = ordre;      (*debug).ordre = ordre;
     (*debug).thread = pthread_self();  
     (*debug).pid = getpid();  
   
 #   ifdef __BACKTRACE  #   ifdef __BACKTRACE
     (*debug).profondeur = backtrace((*debug).pile, PROFONDEUR_PILE);      (*debug).profondeur = backtrace((*debug).pile, PROFONDEUR_PILE);
 #   endif  #   endif
   
     pthread_mutex_unlock(&mutex_allocation);  
   
     if (((*debug).fonction = malloc((strlen(fonction) + 1) *      if (((*debug).fonction = malloc((strlen(fonction) + 1) *
             sizeof(unsigned char))) == NULL)              sizeof(unsigned char))) == NULL)
     {      {
           pthread_mutex_unlock(&mutex_allocation);
         return(NULL);          return(NULL);
     }      }
   
     if (((*debug).argument = malloc((strlen(argument) + 1) *      if (((*debug).argument = malloc((strlen(argument) + 1) *
             sizeof(unsigned char))) == NULL)              sizeof(unsigned char))) == NULL)
     {      {
           pthread_mutex_unlock(&mutex_allocation);
         return(NULL);          return(NULL);
     }      }
   
     strcpy((*debug).fonction, fonction);      strcpy((*debug).fonction, fonction);
     strcpy((*debug).argument, argument);      strcpy((*debug).argument, argument);
   
       pthread_mutex_unlock(&mutex_allocation);
     ordre++;      ordre++;
   
     return((*debug).pointeur);      return((*debug).pointeur);
Line 3659  debug_memoire_modification(void *pointeu Line 3694  debug_memoire_modification(void *pointeu
                 return(NULL);                  return(NULL);
             }              }
   
             pthread_mutex_unlock(&mutex_allocation);  
   
             if (((*element_courant).pointeur = realloc(pointeur, taille))              if (((*element_courant).pointeur = realloc(pointeur, taille))
                     == NULL)                      == NULL)
             {              {
                   pthread_mutex_unlock(&mutex_allocation);
                 return(NULL);                  return(NULL);
             }              }
   
Line 3675  debug_memoire_modification(void *pointeu Line 3709  debug_memoire_modification(void *pointeu
             if (((*element_courant).fonction = malloc((strlen(fonction) + 1) *              if (((*element_courant).fonction = malloc((strlen(fonction) + 1) *
                     sizeof(unsigned char))) == NULL)                      sizeof(unsigned char))) == NULL)
             {              {
                   pthread_mutex_unlock(&mutex_allocation);
                 return(NULL);                  return(NULL);
             }              }
   
             if (((*element_courant).argument = malloc((strlen(argument) + 1) *              if (((*element_courant).argument = malloc((strlen(argument) + 1) *
                     sizeof(unsigned char))) == NULL)                      sizeof(unsigned char))) == NULL)
             {              {
                   pthread_mutex_unlock(&mutex_allocation);
                 return(NULL);                  return(NULL);
             }              }
   
             strcpy((*element_courant).fonction, fonction);              strcpy((*element_courant).fonction, fonction);
             strcpy((*element_courant).argument, argument);              strcpy((*element_courant).argument, argument);
   
               pthread_mutex_unlock(&mutex_allocation);
   
             return((*element_courant).pointeur);              return((*element_courant).pointeur);
         }          }
     }      }
Line 3741  debug_memoire_retrait(void *pointeur) Line 3779  debug_memoire_retrait(void *pointeur)
 }  }
   
 void  void
 debug_memoire_verification(struct_processus *s_etat_processus)  debug_memoire_verification()
 {  {
 #   ifdef __BACKTRACE  #   ifdef __BACKTRACE
     char            **appels;      char            **appels;
 #   endif  
   
     int             j;      int             j;
   #   endif
   
     integer8        i;      integer8        i;
   
     struct_memoire  *element_courant;      struct_memoire  *element_courant;
     struct_memoire  *element_suivant;      struct_memoire  *element_suivant;
   
     fprintf(stderr, "[%d-%llu] MEMORY LEAK\n",      fprintf(stderr, "[%d-%llu] LIST OF MEMORY LEAKS\n",
             getpid(), (unsigned long long) pthread_self());              getpid(), (unsigned long long) pthread_self());
   
     pthread_mutex_lock(&mutex_allocation);      pthread_mutex_lock(&mutex_allocation);
Line 3764  debug_memoire_verification(struct_proces Line 3802  debug_memoire_verification(struct_proces
   
     while(element_courant != NULL)      while(element_courant != NULL)
     {      {
         if (((*element_courant).pid == getpid()) &&          fprintf(stderr, "[%d-%llu] MEDITATION %lld (%llu)\n", getpid(),
                 (pthread_equal((*element_courant).thread, pthread_self()) != 0))                  (unsigned long long) pthread_self(), i,
                   (*element_courant).ordre);
           fprintf(stderr, "[%d-%llu] P: %p, F: %s(), L: %lu, S: %d\n",
                   getpid(), (unsigned long long) pthread_self(),
                   (*element_courant).pointeur,
                   (*element_courant).fonction, (*element_courant).ligne,
                   (int) (*element_courant).taille);
           fprintf(stderr, "[%d-%llu] A: %s\n", getpid(),
                   (unsigned long long) pthread_self(),
                   (*element_courant).argument);
   
           if (strstr((*element_courant).argument, "sizeof(unsigned char)")
                   != NULL)
         {          {
             fprintf(stderr, "[%d-%llu] MEDITATION %lld (%llu)\n", getpid(),              fprintf(stderr, "[%d-%llu] ", getpid(),
                     (unsigned long long) pthread_self(), i,                      (unsigned long long) pthread_self());
                     (*element_courant).ordre);              fprintf(stderr, "O: %s\n", (unsigned char *)
             fprintf(stderr, "[%d-%llu] P: %p, F: %s(), L: %lu, S: %d\n",                      (*element_courant).pointeur);
                     getpid(), (unsigned long long) pthread_self(),          }
                     (*element_courant).pointeur,          else if (strcmp((*element_courant).argument, "sizeof(struct_objet)")
                     (*element_courant).fonction, (*element_courant).ligne,                  == 0)
                     (int) (*element_courant).taille);          {
             fprintf(stderr, "[%d-%llu] A: %s\n", getpid(),              fprintf(stderr, "[%d-%llu] ", getpid(),
                     (unsigned long long) pthread_self(),                      (unsigned long long) pthread_self());
                     (*element_courant).argument);              fprintf(stderr, "O: %d\n", (*((struct_objet *)
                       (*element_courant).pointeur)).type);
           }
           else if (strcmp((*element_courant).argument,
                   "sizeof(struct_liste_chainee)") == 0)
           {
               fprintf(stderr, "[%d-%llu] ", getpid(),
                       (unsigned long long) pthread_self());
               fprintf(stderr, "O: data=%p next=%p\n", (*((struct_liste_chainee *)
                       (*element_courant).pointeur)).donnee,
                       (*((struct_liste_chainee *) (*element_courant).pointeur))
                       .suivant);
           }
   
 #           ifdef __BACKTRACE  #       ifdef __BACKTRACE
             appels = backtrace_symbols((*element_courant).pile,          appels = backtrace_symbols((*element_courant).pile,
                     (*element_courant).profondeur);                  (*element_courant).profondeur);
   
             fprintf(stderr, "[%d-%llu] BACKTRACE\n",          fprintf(stderr, "[%d-%llu] BACKTRACE\n",
                     getpid(), (unsigned long long) pthread_self());                  getpid(), (unsigned long long) pthread_self());
   
             if (appels != NULL)          if (appels != NULL)
           {
               for(j = 0; j < (*element_courant).profondeur; j++)
             {              {
                 for(j = 0; j < (*element_courant).profondeur; j++)                  fprintf(stderr, "[%d-%llu] %s\n", getpid(),
                 {                          (unsigned long long) pthread_self(), appels[j]);
                     fprintf(stderr, "[%d-%llu] %s\n", getpid(),  
                             (unsigned long long) pthread_self(), appels[j]);  
                 }  
   
                 free(appels);  
             }              }
 #           endif  
   
             fprintf(stderr, "\n");  
   
             i++;              free(appels);
         }          }
   #       endif
   
           fprintf(stderr, "\n");
   
           i++;
   
         element_suivant = (*element_courant).suivant;          element_suivant = (*element_courant).suivant;
   
   #       ifndef CORE_DUMP
         free((*element_courant).fonction);          free((*element_courant).fonction);
         free((*element_courant).argument);          free((*element_courant).argument);
         free(element_courant);          free(element_courant);
   #       endif
   
         element_courant = element_suivant;          element_courant = element_suivant;
     }      }
   
Line 3817  debug_memoire_verification(struct_proces Line 3882  debug_memoire_verification(struct_proces
   
     return;      return;
 }  }
   
   void
   debug_memoire_reinitialisation()
   {
       ordre = 0;
       debug = NULL;
   
       pthread_mutex_trylock(&mutex_allocation);
       pthread_mutex_unlock(&mutex_allocation);
   
       return;
   }
   
   void
   analyse_post_mortem()
   {
   #   ifdef CORE_DUMP
       BUG(debug != NULL, uprintf("[%d-%llu] CREATE CORE DUMP FILE FOR "
               "POST MORTEM ANALYZE\n", getpid(),
               (unsigned long long) pthread_self()));
   #   endif
   
       return;
   }
   
 #endif  #endif
   

Removed from v.1.16  
changed lines
  Added in v.1.19


CVSweb interface <joel.bertrand@systella.fr>