--- rpl/src/gestion_objets.c 2010/05/16 19:36:20 1.17 +++ rpl/src/gestion_objets.c 2010/05/19 09:22:34 1.18 @@ -877,14 +877,21 @@ liberation(struct_processus *s_etat_proc { if (decrementation_atomique(s_objet) > 0) { - liberation(s_etat_processus, (*((struct_fichier *) - (*s_objet).objet)).format); + 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; } liberation(s_etat_processus, (*((struct_fichier *) (*s_objet).objet)).format); - free((unsigned char *) (*((struct_fichier *) (*s_objet).objet)).nom); free((struct_fichier *) ((*s_objet).objet)); @@ -1210,6 +1217,14 @@ liberation(struct_processus *s_etat_proc { 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; @@ -1217,6 +1232,7 @@ liberation(struct_processus *s_etat_proc liberation(s_etat_processus, (*((struct_socket *) (*s_objet).objet)).format); + free((unsigned char *) (*((struct_socket *) (*s_objet).objet)) .adresse); free((unsigned char *) (*((struct_socket *) (*s_objet).objet)) @@ -2278,9 +2294,10 @@ copie_objet(struct_processus *s_etat_pro { incrementation_atomique(s_objet); - if (((*((struct_socket *) ((*s_nouvel_objet).objet))).format = - copie_objet(s_etat_processus, (*((struct_socket *) - ((*s_objet).objet))).format, 'P')) == NULL) + if (((*((struct_socket *) ((*s_objet).objet))) + .format = copie_objet(s_etat_processus, + (*((struct_socket *) ((*s_objet).objet))).format, 'P')) + == NULL) { return(NULL); } @@ -3582,7 +3599,7 @@ static unsigned long long ordre = 0; static pthread_mutex_t mutex_allocation = PTHREAD_MUTEX_INITIALIZER; #define check(a, b) ((strcmp(#a, fonction) == 0) && (ligne == b)) -#define CORE_DUMP +#undef CORE_DUMP void * debug_memoire_ajout(size_t taille, const unsigned char *fonction, @@ -3615,23 +3632,24 @@ debug_memoire_ajout(size_t taille, const (*debug).profondeur = backtrace((*debug).pile, PROFONDEUR_PILE); # endif - pthread_mutex_unlock(&mutex_allocation); - if (((*debug).fonction = malloc((strlen(fonction) + 1) * sizeof(unsigned char))) == NULL) { + pthread_mutex_unlock(&mutex_allocation); return(NULL); } if (((*debug).argument = malloc((strlen(argument) + 1) * sizeof(unsigned char))) == NULL) { + pthread_mutex_unlock(&mutex_allocation); return(NULL); } strcpy((*debug).fonction, fonction); strcpy((*debug).argument, argument); + pthread_mutex_unlock(&mutex_allocation); ordre++; return((*debug).pointeur); @@ -3676,11 +3694,10 @@ debug_memoire_modification(void *pointeu return(NULL); } - pthread_mutex_unlock(&mutex_allocation); - if (((*element_courant).pointeur = realloc(pointeur, taille)) == NULL) { + pthread_mutex_unlock(&mutex_allocation); return(NULL); } @@ -3692,18 +3709,22 @@ debug_memoire_modification(void *pointeu if (((*element_courant).fonction = malloc((strlen(fonction) + 1) * sizeof(unsigned char))) == NULL) { + pthread_mutex_unlock(&mutex_allocation); return(NULL); } if (((*element_courant).argument = malloc((strlen(argument) + 1) * sizeof(unsigned char))) == NULL) { + pthread_mutex_unlock(&mutex_allocation); return(NULL); } strcpy((*element_courant).fonction, fonction); strcpy((*element_courant).argument, argument); + pthread_mutex_unlock(&mutex_allocation); + return((*element_courant).pointeur); } } @@ -3793,6 +3814,33 @@ debug_memoire_verification() (unsigned long long) pthread_self(), (*element_courant).argument); + if (strstr((*element_courant).argument, "sizeof(unsigned char)") + != NULL) + { + fprintf(stderr, "[%d-%llu] ", getpid(), + (unsigned long long) pthread_self()); + fprintf(stderr, "O: %s\n", (unsigned char *) + (*element_courant).pointeur); + } + else if (strcmp((*element_courant).argument, "sizeof(struct_objet)") + == 0) + { + fprintf(stderr, "[%d-%llu] ", getpid(), + (unsigned long long) pthread_self()); + 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 appels = backtrace_symbols((*element_courant).pile, (*element_courant).profondeur); @@ -3834,6 +3882,18 @@ debug_memoire_verification() return; } + +void +debug_memoire_reinitialisation() +{ + ordre = 0; + debug = NULL; + + pthread_mutex_trylock(&mutex_allocation); + pthread_mutex_unlock(&mutex_allocation); + + return; +} void analyse_post_mortem()