On Sunday 14 October 2012 16:22:17 Sami Kerola wrote: > +static int shmctl_info_wrapper(int maxid, int id, struct shm_data **shmds, > + int use_proc) > +{ > + char skipheader[1024]; > + int i, shmid; > + struct shm_data *shmdsp; > + > + struct shmid_ds shmseg; > + struct ipc_perm *ipcp = &shmseg.shm_perm; > + > + *shmds = xmalloc(sizeof(struct shm_data)); > + shmdsp = *shmds; could just one line: shmdsp = *shmds = xmalloc(sizeof(struct shm_data)); > + shmdsp->next = NULL; > + if (use_proc) { > + FILE *f; > + if ((f = fopen(_PATH_PROC_IPCSHM, "r")) == NULL) > + return -1; doesn't this leak memory with shmds ? > + fgets(skipheader, 1024, f); why not just fseek() ? does that not work on the /proc path ? > + for (i = 0; !feof(f); i++) { > + fscanf(f, > + "%10d %10d %4o " SIZE_SPEC > + " %5lu %5lu %5lu %5u %5u %5u %5u %10lu %10lu %10lu " > + SIZE_SPEC " " SIZE_SPEC "\n", > + &(shmdsp->shm_perm.key), > + &(shmdsp->shm_perm.id), > + &(shmdsp->shm_perm.mode), > + &(shmdsp->shm_segsz), > + &(shmdsp->shm_cprid), > + &(shmdsp->shm_lprid), > + &(shmdsp->shm_nattch), > + &(shmdsp->shm_perm.uid), > + &(shmdsp->shm_perm.gid), > + &(shmdsp->shm_perm.cuid), > + &(shmdsp->shm_perm.cgid), > + &(shmdsp->shm_atim), > + &(shmdsp->shm_dtim), > + &(shmdsp->shm_ctim), > + &(shmdsp->shm_rss), > + &(shmdsp->shm_swp) > + ); shouldn't this check the return of fscanf() ? > -void do_shm (char format, int use_proc) > +static void freeshms(struct shm_data *shmds) > { > - int maxid, shmid, id; > - struct shmid_ds shmseg; > + while (shmds) { > + struct shm_data *next = shmds->next; > + free(shmds); > + shmds = next; > + } > + return; > +} pointless return statement -> delete -mike
Attachment:
signature.asc
Description: This is a digitally signed message part.