Skip to content

Commit

Permalink
Merge pull request #504 from tasleson/memleak
Browse files Browse the repository at this point in the history
Fix Memleak warning
  • Loading branch information
tasleson authored Apr 6, 2022
2 parents 174005a + 0f41e21 commit ae02fc0
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 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 All @@ -735,16 +735,17 @@ int _sg_parse_vpd_83(char *err_msg, uint8_t *vpd_data,
rc = LSM_ERR_NO_MEMORY;
goto out;
}
(*dps)[*dp_count] = dp;
++*dp_count;

dp_header = (struct _sg_t10_vpd83_dp_header *)p;
memcpy(&dp->header, dp_header, sizeof(struct _sg_t10_vpd83_dp_header));
memcpy(dp->designator, p + sizeof(struct _sg_t10_vpd83_dp_header),
dp_header->designator_len);

p += dp_header->designator_len + sizeof(struct _sg_t10_vpd83_dp_header);
continue;

(*dps)[*dp_count] = dp;
++*dp_count;
dp = NULL;
}

out:
Expand All @@ -759,14 +760,8 @@ int _sg_parse_vpd_83(char *err_msg, uint8_t *vpd_data,
}

static struct _sg_t10_vpd83_dp *_sg_t10_vpd83_dp_new(void) {
struct _sg_t10_vpd83_dp *dp = NULL;

dp = (struct _sg_t10_vpd83_dp *)malloc(sizeof(struct _sg_t10_vpd83_dp));

if (dp != NULL) {
memset(dp, 0, sizeof(struct _sg_t10_vpd83_dp));
}
return dp;
return (struct _sg_t10_vpd83_dp *)calloc(1,
sizeof(struct _sg_t10_vpd83_dp));
}

static int _sg_io_open(char *err_msg, const char *disk_path, int *fd,
Expand Down

0 comments on commit ae02fc0

Please sign in to comment.