From 0f41e217eb27c37929bc42869aab9cccf34d7928 Mon Sep 17 00:00:00 2001 From: Tony Asleson Date: Wed, 6 Apr 2022 11:25:22 -0500 Subject: [PATCH] libsg.c: Use calloc When we allocate memory for an array of structure pointers it would be better to ensure all the address locations are zero. Then if an error is made with the number of elements in the array, we won't try to free uninitialized memory. Signed-off-by: Tony Asleson --- c_binding/libsg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/c_binding/libsg.c b/c_binding/libsg.c index 23f217b6..099431bb 100644 --- a/c_binding/libsg.c +++ b/c_binding/libsg.c @@ -719,8 +719,8 @@ int _sg_parse_vpd_83(char *err_msg, uint8_t *vpd_data, if (i == 0) goto out; - *dps = (struct _sg_t10_vpd83_dp **)malloc( - sizeof(struct _sg_t10_vpd83_dp *) * i); + *dps = (struct _sg_t10_vpd83_dp **)calloc( + i, sizeof(struct _sg_t10_vpd83_dp *)); if (*dps == NULL) { rc = LSM_ERR_NO_MEMORY;