Skip to content

Commit

Permalink
Make sure memory is cleaned up in errlud_i2c.C
Browse files Browse the repository at this point in the history
This small update is based on review comments
to a previous fix of runtime i2c crashing issue.
Previous Change: I6c912e71b22da80b166e13dc66bdf0e5a51abfbb

Change-Id: If9c33773777943a67f9a5e00d48f0647b45c8406
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/75235
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Reviewed-by: Nicholas E. Bofferding <bofferdn@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com>
Reviewed-by: Christian R. Geddes <crgeddes@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
  • Loading branch information
mderkse1 authored and Nicholas E. Bofferding committed Apr 15, 2019
1 parent deec965 commit ecfbca4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/usr/i2c/errlud_i2c.C
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ UdI2CParms::UdI2CParms( uint8_t i_opType,
if (i_args.i2cMuxPath)
{
l_muxPath = i_args.i2cMuxPath->toString();
l_muxPathSize = strlen(l_muxPath);
if (l_muxPath != nullptr)
{
l_muxPathSize = strlen(l_muxPath);
}
}
char * l_pBuf = reinterpret_cast<char *>(
reallocUsrBuf(sizeof(uint8_t)*2
Expand Down Expand Up @@ -173,16 +176,14 @@ UdI2CParms::UdI2CParms( uint8_t i_opType,

if (l_muxPathSize > 0)
{
memcpy(l_pBuf, l_muxPath, strlen(l_muxPath));
l_pBuf += strlen(l_muxPath);

// done with muxPath so free it here
free(l_muxPath);
l_muxPath = nullptr;
l_muxPathSize = 0;
memcpy(l_pBuf, l_muxPath, l_muxPathSize);
l_pBuf += l_muxPathSize;
}
*l_pBuf = '\0'; // add a terminator for ease of parsing
++l_pBuf;

free(l_muxPath);
l_muxPath = nullptr;
}

//------------------------------------------------------------------------------
Expand Down

0 comments on commit ecfbca4

Please sign in to comment.