summaryrefslogtreecommitdiffstats
path: root/sys-utils/ipcutils.c
diff options
context:
space:
mode:
authorKarel Zak2012-11-05 17:28:07 +0100
committerKarel Zak2012-11-23 14:58:21 +0100
commit7d94d1cebc296cfceb991240f3c2e19028a22adc (patch)
treec71aff2da64abff47cd0bc8241f91f47207bd064 /sys-utils/ipcutils.c
parentipcs: clean up do_shm() (diff)
downloadkernel-qcow2-util-linux-7d94d1cebc296cfceb991240f3c2e19028a22adc.tar.gz
kernel-qcow2-util-linux-7d94d1cebc296cfceb991240f3c2e19028a22adc.tar.xz
kernel-qcow2-util-linux-7d94d1cebc296cfceb991240f3c2e19028a22adc.zip
ipcs: fix ipc_shm_get_info(), use calloc
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/ipcutils.c')
-rw-r--r--sys-utils/ipcutils.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/sys-utils/ipcutils.c b/sys-utils/ipcutils.c
index 959b70c63..3b52a7e6b 100644
--- a/sys-utils/ipcutils.c
+++ b/sys-utils/ipcutils.c
@@ -98,7 +98,7 @@ int ipc_shm_get_info(int id, struct shm_data **shmds)
struct shm_data *p;
struct shm_info dummy;
- p = *shmds = xmalloc(sizeof(struct shm_data));
+ p = *shmds = xcalloc(1, sizeof(struct shm_data));
p->next = NULL;
f = path_fopen("r", 0, _PATH_PROC_SYSV_SHM);
@@ -107,7 +107,7 @@ int ipc_shm_get_info(int id, struct shm_data **shmds)
while (fgetc(f) != '\n'); /* skip header */
- for (i = 0; !feof(f); i++) {
+ while (feof(f) == 0) {
if (fscanf(f,
"%d %d %o %"SCNu64 " %u %u "
"%"SCNu64 " %u %u %u %u %"SCNu64 " %"SCNu64 " %"SCNu64
@@ -130,15 +130,19 @@ int ipc_shm_get_info(int id, struct shm_data **shmds)
&p->shm_swp) != 16)
continue;
- if (id > -1 && id != p->shm_perm.id) {
- i--;
- continue; /* id specified, but does not match */
- }
- if (id < 0) {
- p->next = xmalloc(sizeof(struct shm_data));
- p = p->next;
- p->next = NULL;
+ if (id > -1) {
+ /* ID specified */
+ if (id == p->shm_perm.id) {
+ i = 1;
+ break;
+ } else
+ continue;
}
+
+ p->next = xcalloc(1, sizeof(struct shm_data));
+ p = p->next;
+ p->next = NULL;
+ i++;
}
if (i == 0)
@@ -187,7 +191,7 @@ fallback:
p->shm_swp = 0xdead;
if (id < 0) {
- p->next = xmalloc(sizeof(struct shm_data));
+ p->next = xcalloc(1, sizeof(struct shm_data));
p = p->next;
p->next = NULL;
i++;