Skip to content

Commit

Permalink
Fix to avoid a memory leak in iRODS API queryCollAclSpecific
Browse files Browse the repository at this point in the history
This iRODS function leaks memory, but by calling a lower level iRODS
API function instead, we can avoid the problem malloc.
  • Loading branch information
kjsanger committed Jan 29, 2025
1 parent b2f4757 commit 7121fdd
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,25 +438,40 @@ json_t *list_permissions(rcComm_t *conn, rodsPath_t *rods_path,
// This specific query reports the groups without expansion. It is used by ils,
// if available and is installed by default on iRODS servers.
genQueryOut_t *query_out = NULL;
int status = queryCollAclSpecific(conn, rods_path->outPath, rods_path->outPath,
&query_out);
// The query returns 4 columns, the last being the user type (e.g. rodsgroup)
// but we only want the first 3, so temporarily decrement the attribute count
// to avoid reporting it.
query_out->attriCnt--;

// We don't use the queryCollAclSpecific function here because it leaks memory:
//
// int status = queryCollAclSpecific(conn, rods_path->outPath, rods_path->outPath,
// &query_out);
//
// Instead call lower level rcSpecificQuery directly, avoiding the problem malloc.
specificQueryInp_t specificQueryInp;
memset(&specificQueryInp, 0, sizeof(specificQueryInp_t));
specificQueryInp.maxRows = MAX_SQL_ROWS;
specificQueryInp.continueInx = 0;
specificQueryInp.sql = "ShowCollAcls";
specificQueryInp.args[0] = rods_path->outPath;

addKeyVal(&specificQueryInp.condInput, ZONE_KW, rods_path->outPath);
logmsg(DEBUG, "Using zone hint '%s'", rods_path->outPath);
int status = rcSpecificQuery(conn, &specificQueryInp, &query_out);
if (status < 0) {
set_baton_error(error, status,
"Failed to query ACL on '%s': error %d",
rods_path->outPath, status);
goto error;
}

// The query returns 4 columns, the last being the user type (e.g. rodsgroup)
// but we only want the first 3, so temporarily decrement the attribute count
// to avoid reporting it.
query_out->attriCnt--;
results = make_json_objects(query_out,
(const char *[]) { JSON_OWNER_KEY, JSON_ZONE_KEY, JSON_LEVEL_KEY });

// Restore the attribute count before calling the free function.
query_out->attriCnt++;

logmsg(DEBUG, "Obtained ACL data on '%s'", rods_path->outPath);
free_query_output(query_out);
break;

Expand Down

0 comments on commit 7121fdd

Please sign in to comment.