From 39ed6501bb3a286600941b600ea40557f8f6a4d8 Mon Sep 17 00:00:00 2001 From: Janani Date: Wed, 28 Jan 2015 14:28:35 +0530 Subject: [PATCH 4/4] lsvpd: Defer the freeing of devSg After calling basename, we need to defer freeing the pointer. This is because the basename function may return pointers to statically allocated memory which may be overwritten by subsequent calls. They may return a pointer to some part of path and hence the string refered to by the path should not be modified or freed until the pointer returned by the function is no longer required. Signed-off-by: Janani Venkataraman Signed-off-by: Kamalesh Babulal Reviewed-by: Naveen N. Rao [Removed redundant return - Vasant] Signed-off-by: Vasant Hegde --- src/internal/sys_interface/sysfs_SCSI_Fill.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/internal/sys_interface/sysfs_SCSI_Fill.cpp b/src/internal/sys_interface/sysfs_SCSI_Fill.cpp index 8190983..8b2ccd4 100755 --- a/src/internal/sys_interface/sysfs_SCSI_Fill.cpp +++ b/src/internal/sys_interface/sysfs_SCSI_Fill.cpp @@ -1463,16 +1463,22 @@ namespace lsvpd if (path == "") return; + devSg = strdup(path.c_str()); + if (devSg == NULL) + return; + sg = basename(devSg); - free(devSg); if (sg == "") - return; + goto out; + cmd = "2>/dev/null iprconfig -c show-details " + sg; - if (HelperFunctions::execCmd(cmd.c_str(), output)) - return; + if (HelperFunctions::execCmd(cmd.c_str(), output)) + goto out; parseIPRData(fillMe, output); +out: + free(devSg); } /******************************************************************** -- 1.9.1