From: Alexander Aring Date: Thu, 11 Mar 2021 14:20:36 -0500 Subject: [Cluster-devel] [PATCH gfs2-utils 2/2] glocktop: allocate fsdlm dynamically In-Reply-To: <20210311192036.17218-1-aahringo@redhat.com> References: <20210311192036.17218-1-aahringo@redhat.com> Message-ID: <20210311192036.17218-3-aahringo@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This patch allocates the fsdlm string dynamically with respect of dlmwaiters. The fsdlm has at least the dlmwaiters length, the 105 bytes are for some other predicted max length strings. Signed-off-by: Alexander Aring --- gfs2/glocktop/glocktop.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gfs2/glocktop/glocktop.c b/gfs2/glocktop/glocktop.c index 9df87d18..0096a2a5 100644 --- a/gfs2/glocktop/glocktop.c +++ b/gfs2/glocktop/glocktop.c @@ -1605,7 +1605,7 @@ static void parse_glocks_file(int fd, const char *fsname, int dlmwaiters, int dlmgrants, int trace_dir_path, int show_held, int help, int summary) { - char fstitle[96], fsdlm[105]; + char fstitle[96], *fsdlm; char ctimestr[64]; time_t t; int i; @@ -1615,7 +1615,12 @@ static void parse_glocks_file(int fd, const char *fsname, int dlmwaiters, strftime(ctimestr, 64, "%a %b %d %T %Y", localtime(&t)); ctimestr[63] = '\0'; memset(fstitle, 0, sizeof(fstitle)); - memset(fsdlm, 0, sizeof(fsdlm)); + fsdlm = calloc(1, 105 + dlmwaiters); + if (!fsdlm) { + printf("Failed to allocate fsdlm\n"); + exit(-1); + } + sprintf(fstitle, "@ %.22s %s ", fsname, ctimestr); if (dlmwaiters) { sprintf(fsdlm, "dlm: %s/%s/%s [", dlm_dirtbl_size, @@ -1628,6 +1633,7 @@ static void parse_glocks_file(int fd, const char *fsname, int dlmwaiters, } attron(A_BOLD); print_it(NULL, "%s @%s %s", NULL, fstitle, hostname, fsdlm); + free(fsdlm); eol(0); attroff(A_BOLD); glock_details(fd, fsname, dlmwaiters, dlmgrants, trace_dir_path, -- 2.26.2