Skip to content

Commit

Permalink
libsg.c: Use calloc
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tasleson committed Apr 6, 2022
1 parent 1bea882 commit 0f41e21
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions c_binding/libsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0f41e21

Please sign in to comment.