Linux-SWAT
Forum Addict!
- Joined
- Feb 13, 2010
- Messages
- 9,188
Hi,
I'm supposed to have a memory leak (clang + -fsanitize=address) in this portion of code. I tried various free(&*) without success.
I'm supposed to have a memory leak (clang + -fsanitize=address) in this portion of code. I tried various free(&*) without success.
pthread_t tid[2];
pthread_mutex_t lock;
struct spectacle {
char spectacle_nom[20];
unsigned short spectacle_places_disponibles;
};
struct msgbuf {
long mtype;
char mtext[MAXSIZE];
};
struct message_msgbuf {
long mtype;
struct requete_info {
char nom[MAXSIZE];
int msqid_demandeur;
int spectacle;
int nb_places_demandees;
} info;
};
sem_t * tsemaphore;
int tshmid_spectacles;
int tmsqid;
tmsqid_demandeur;
tspectacle;
tnb_places_demandees;
void Fils_Reservation(sem_t * semaphore, int shmid_spectacles, int msqid_demandeur, int spectacle, int nb_places_demandees){
printf("fils réserve\n");
sem_wait (semaphore);
void *addr = Attachement_SHM(shmid_spectacles);
struct spectacle *shared_spectacles = (struct spectacle*)addr;
if ((shared_spectacles[spectacle].spectacle_places_disponibles > 0) && (shared_spectacles[spectacle].spectacle_places_disponibles - nb_places_demandees >= 0)) {
shared_spectacles[spectacle].spectacle_places_disponibles = shared_spectacles[spectacle].spectacle_places_disponibles - nb_places_demandees;
printf("fils réserve OK\n");
Envoi_Entier_Mqueue(msqid_demandeur, 2, 1);
}
else {
printf("fils réserve NOK\n");
Envoi_Entier_Mqueue(msqid_demandeur, 2, 0);
}
sem_post (semaphore);
Detachement_SHM(addr);
exit(0);
}
pthread_mutex_t lock;
struct spectacle {
char spectacle_nom[20];
unsigned short spectacle_places_disponibles;
};
struct msgbuf {
long mtype;
char mtext[MAXSIZE];
};
struct message_msgbuf {
long mtype;
struct requete_info {
char nom[MAXSIZE];
int msqid_demandeur;
int spectacle;
int nb_places_demandees;
} info;
};
sem_t * tsemaphore;
int tshmid_spectacles;
int tmsqid;
tmsqid_demandeur;
tspectacle;
tnb_places_demandees;
void Fils_Reservation(sem_t * semaphore, int shmid_spectacles, int msqid_demandeur, int spectacle, int nb_places_demandees){
printf("fils réserve\n");
sem_wait (semaphore);
void *addr = Attachement_SHM(shmid_spectacles);
struct spectacle *shared_spectacles = (struct spectacle*)addr;
if ((shared_spectacles[spectacle].spectacle_places_disponibles > 0) && (shared_spectacles[spectacle].spectacle_places_disponibles - nb_places_demandees >= 0)) {
shared_spectacles[spectacle].spectacle_places_disponibles = shared_spectacles[spectacle].spectacle_places_disponibles - nb_places_demandees;
printf("fils réserve OK\n");
Envoi_Entier_Mqueue(msqid_demandeur, 2, 1);
}
else {
printf("fils réserve NOK\n");
Envoi_Entier_Mqueue(msqid_demandeur, 2, 0);
}
sem_post (semaphore);
Detachement_SHM(addr);
exit(0);
}