util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: Sami Kerola <kerolasa@iki.fi>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH 05/13] ipcs: read shared memory values from /proc
Date: Sun, 14 Oct 2012 22:07:24 -0400	[thread overview]
Message-ID: <201210142207.24981.vapier@gentoo.org> (raw)
In-Reply-To: <1350246145-10600-6-git-send-email-kerolasa@iki.fi>

[-- Attachment #1: Type: Text/Plain, Size: 1886 bytes --]

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 #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

  reply	other threads:[~2012-10-15  2:07 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
2012-10-14 20:22 ` [PATCH 01/13] ipcs: add data structures to read state from /proc & /sys Sami Kerola
2012-10-14 20:22 ` [PATCH 02/13] ipcs: add /proc and /sys path definitions Sami Kerola
2012-11-05 16:43   ` Karel Zak
2012-10-14 20:22 ` [PATCH 03/13] ipcs: determine ipc limits from /proc Sami Kerola
2012-10-15  2:00   ` Mike Frysinger
2012-11-05 16:49   ` Karel Zak
2012-10-14 20:22 ` [PATCH 04/13] ipcs: add new permissions printing function Sami Kerola
2012-10-14 20:22 ` [PATCH 05/13] ipcs: read shared memory values from /proc Sami Kerola
2012-10-15  2:07   ` Mike Frysinger [this message]
2012-10-14 20:22 ` [PATCH 06/13] ipcs: read message queue " Sami Kerola
2012-10-14 20:22 ` [PATCH 07/13] ipsc: read semaphore " Sami Kerola
2012-10-14 20:22 ` [PATCH 08/13] ipcs: clean up permissions printing Sami Kerola
2012-10-14 20:22 ` [PATCH 09/13] ipcs: make individual shared memory id printing to use /proc Sami Kerola
2012-11-05 16:53   ` Karel Zak
2012-10-14 20:22 ` [PATCH 10/13] ipcs: make individual message queue " Sami Kerola
2012-10-14 20:22 ` [PATCH 11/13] ipcs: make individual semaphore " Sami Kerola
2012-10-14 20:22 ` [PATCH 12/13] ipcs: validate numeric user input Sami Kerola
2012-10-14 20:22 ` [PATCH 13/13] docs: update TODO Sami Kerola
     [not found] ` <20121015153924.GL18377@x2.net.home>
2012-10-22 20:23   ` [PATCH 00/13] make ipcs to use proc Sami Kerola
2012-11-05 16:42 ` Karel Zak
2012-11-07  9:40   ` Sami Kerola
2012-11-07 10:01     ` Karel Zak
2012-11-11 23:01       ` Sami Kerola

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201210142207.24981.vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).