in src/utils/workflow_utils/src/workflow_utils.c [243:339]
static bool ADUC_RelatedFile_Init(
ADUC_RelatedFile* relatedFile,
const char* fileId,
const char* downloadUri,
const char* fileName,
size_t hashCount,
ADUC_Hash* hashes,
size_t propertiesCount,
ADUC_Property* properties)
{
bool success = false;
ADUC_Property* tempPropertiesArray = NULL;
if (relatedFile == NULL || fileId == NULL || downloadUri == NULL || fileName == NULL || hashes == NULL
|| properties == NULL)
{
return false;
}
relatedFile->HashCount = hashCount;
ADUC_Hash* tempHashArray = calloc(hashCount, sizeof(*tempHashArray));
if (tempHashArray == NULL)
{
goto done;
}
for (size_t i = 0; i < hashCount; ++i)
{
if (!ADUC_Hash_Init(&tempHashArray[i], hashes[i].value, hashes[i].type))
{
goto done;
}
}
relatedFile->PropertiesCount = propertiesCount;
tempPropertiesArray = (ADUC_Property*)malloc(propertiesCount * sizeof(ADUC_Property));
if (tempPropertiesArray == NULL)
{
goto done;
}
for (size_t i = 0; i < propertiesCount; ++i)
{
if (!ADUC_Property_Init(&tempPropertiesArray[i], properties[i].Name, properties[i].Value))
{
goto done;
}
}
if (mallocAndStrcpy_s(&(relatedFile->FileId), fileId) != 0)
{
goto done;
}
if (mallocAndStrcpy_s(&(relatedFile->DownloadUri), downloadUri) != 0)
{
goto done;
}
if (mallocAndStrcpy_s(&(relatedFile->FileName), fileName) != 0)
{
goto done;
}
// transfer ownership
relatedFile->HashCount = hashCount;
relatedFile->Hash = tempHashArray;
tempHashArray = NULL;
relatedFile->PropertiesCount = propertiesCount;
relatedFile->Properties = tempPropertiesArray;
tempPropertiesArray = NULL;
success = true;
done:
if (!success)
{
if (tempHashArray != NULL)
{
ADUC_Hash_FreeArray(hashCount, tempHashArray);
tempHashArray = NULL;
}
if (tempPropertiesArray != NULL)
{
ADUC_Properties_FreeArray(propertiesCount, tempPropertiesArray);
tempPropertiesArray = NULL;
}
// do not call ADUC_RelatedFile_UnInit(relatedFile) here as it will
// get cleaned up by caller for the failure.
}
return success;
}