From: Karel Zak Date: Mon, 5 Nov 2012 16:28:07 +0000 (+0100) Subject: ipcs: fix ipc_shm_get_info(), use calloc X-Git-Tag: v2.23-rc1~494 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7d94d1cebc296cfceb991240f3c2e19028a22adc;p=thirdparty%2Futil-linux.git ipcs: fix ipc_shm_get_info(), use calloc Signed-off-by: Karel Zak --- diff --git a/sys-utils/ipcutils.c b/sys-utils/ipcutils.c index 959b70c63f..3b52a7e6b8 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++;