Skip to content

Commit

Permalink
[#288] Fix memleaks discovered by ASAN
Browse files Browse the repository at this point in the history
  • Loading branch information
alanking committed Dec 20, 2024
1 parent 3dbd014 commit c1a07b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "irods/private/storage_tiering/exec_as_user.hpp"

#include <irods/filesystem.hpp>
#include <irods/irods_at_scope_exit.hpp>
#include <irods/irods_query.hpp>

#undef LIST
Expand Down Expand Up @@ -118,6 +119,7 @@ namespace {
}

dataObjInp_t data_obj_inp{};
const auto free_cond_input = irods::at_scope_exit{[&data_obj_inp] { clearKeyVal(&data_obj_inp.condInput); }};
rstrcpy(data_obj_inp.objPath, _object_path.c_str(), MAX_NAME_LEN);
data_obj_inp.createMode = getDefFileMode();
addKeyVal(&data_obj_inp.condInput, RESC_NAME_KW, _source_resource.c_str());
Expand Down Expand Up @@ -149,6 +151,7 @@ namespace {
}

dataObjInp_t obj_inp{};
const auto free_cond_input = irods::at_scope_exit{[&obj_inp] { clearKeyVal(&obj_inp.condInput); }};
rstrcpy(
obj_inp.objPath,
_object_path.c_str(),
Expand Down Expand Up @@ -192,6 +195,7 @@ namespace {
const_cast<char*>(_attribute.c_str()),
const_cast<char*>(ts.c_str()),
""};
const auto free_cond_input = irods::at_scope_exit{[&avuOp] { clearKeyVal(&avuOp.condInput); }};

if (_comm->clientUser.authInfo.authFlag >= LOCAL_PRIV_USER_AUTH) {
addKeyVal(&avuOp.condInput, ADMIN_KW, "");
Expand Down
19 changes: 18 additions & 1 deletion src/storage_tiering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,25 @@ namespace irods {
};

execMyRuleInp_t exec_inp{};
rstrcpy(exec_inp.myRule, rule_obj.dump().c_str(), META_STR_LEN);
msParamArray_t* out_arr{};
// Capture out_arr pointer by reference because it is still nullptr at this point.
const auto free_inputs_and_outputs = irods::at_scope_exit{[&exec_inp, &out_arr] {
clearKeyVal(&exec_inp.condInput);

if (exec_inp.inpParamArray) {
// The second parameter with a value of 1 instructs the function to free the "inOutStruct".
clearMsParamArray(exec_inp.inpParamArray, 1);
std::free(exec_inp.inpParamArray);
}

if (out_arr) {
// The second parameter with a value of 1 instructs the function to free the "inOutStruct".
clearMsParamArray(out_arr, 1);
std::free(out_arr);
}
}};

rstrcpy(exec_inp.myRule, rule_obj.dump().c_str(), META_STR_LEN);
addKeyVal(
&exec_inp.condInput
, irods::KW_CFG_INSTANCE_NAME
Expand Down

0 comments on commit c1a07b2

Please sign in to comment.