Skip to content

Commit

Permalink
Fix memleak ADUC_ParseUpdateType (#351)
Browse files Browse the repository at this point in the history
* fix memleak ADUC_ParseUpdateType

* clang-format
  • Loading branch information
jw-msft authored Jan 19, 2023
1 parent 53647c3 commit 2c264e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ ADUC_Result SWUpdateHandlerImpl::Download(const tagADUC_WorkflowData* workflowDa
done:
workflow_free_string(workFolder);
workflow_free_file_entity(entity);
free(updateName);

return result;
}
Expand Down Expand Up @@ -326,10 +327,7 @@ ADUC_Result SWUpdateHandlerImpl::Apply(const tagADUC_WorkflowData* workflowData)
CancelApply(ADUC_LOG_FOLDER);
}

result = {
.ResultCode = ADUC_Result_Success,
.ExtendedResultCode = 0
};
result = { .ResultCode = ADUC_Result_Success, .ExtendedResultCode = 0 };

done:
workflow_free_string(workFolder);
Expand Down
14 changes: 14 additions & 0 deletions src/utils/c_utils/tests/c_utils_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ TEST_CASE("ADUC_ParseUpdateType and atoui")
char* updateTypeName = nullptr;
unsigned int updateTypeVersion;
CHECK(!ADUC_ParseUpdateType(updateType, &updateTypeName, &updateTypeVersion));
free(updateTypeName);
}

SECTION("Missing Update Name")
Expand All @@ -231,6 +232,7 @@ TEST_CASE("ADUC_ParseUpdateType and atoui")
char* updateTypeName = nullptr;
unsigned int updateTypeVersion;
CHECK(!ADUC_ParseUpdateType(updateType, &updateTypeName, &updateTypeVersion));
free(updateTypeName);
}

SECTION("Missing Version Number")
Expand All @@ -239,6 +241,7 @@ TEST_CASE("ADUC_ParseUpdateType and atoui")
char* updateTypeName = nullptr;
unsigned int updateTypeVersion;
CHECK(!ADUC_ParseUpdateType(updateType, &updateTypeName, &updateTypeVersion));
free(updateTypeName);
}

SECTION("Missing Delimiter")
Expand All @@ -247,6 +250,7 @@ TEST_CASE("ADUC_ParseUpdateType and atoui")
char* updateTypeName = nullptr;
unsigned int updateTypeVersion;
CHECK(!ADUC_ParseUpdateType(updateType, &updateTypeName, &updateTypeVersion));
free(updateTypeName);
}

SECTION("Negative Number")
Expand All @@ -255,6 +259,7 @@ TEST_CASE("ADUC_ParseUpdateType and atoui")
char* updateTypeName = nullptr;
unsigned int updateTypeVersion;
CHECK(!ADUC_ParseUpdateType(updateType, &updateTypeName, &updateTypeVersion));
free(updateTypeName);
}

SECTION("Ransome Negative Number")
Expand All @@ -263,6 +268,7 @@ TEST_CASE("ADUC_ParseUpdateType and atoui")
char* updateTypeName = nullptr;
unsigned int updateTypeVersion;
CHECK(!ADUC_ParseUpdateType(updateType, &updateTypeName, &updateTypeVersion));
free(updateTypeName);
}

SECTION("Zero")
Expand All @@ -273,6 +279,7 @@ TEST_CASE("ADUC_ParseUpdateType and atoui")
CHECK(ADUC_ParseUpdateType(updateType, &updateTypeName, &updateTypeVersion));
CHECK_THAT(updateTypeName, Equals("microsoft/apt"));
CHECK(updateTypeVersion == 0);
free(updateTypeName);
}

SECTION("Positive Number")
Expand All @@ -283,6 +290,7 @@ TEST_CASE("ADUC_ParseUpdateType and atoui")
CHECK(ADUC_ParseUpdateType(updateType, &updateTypeName, &updateTypeVersion));
CHECK_THAT(updateTypeName, Equals("microsoft/apt"));
CHECK(updateTypeVersion == 1);
free(updateTypeName);
}

SECTION("Positive Large Number")
Expand All @@ -293,6 +301,7 @@ TEST_CASE("ADUC_ParseUpdateType and atoui")
CHECK(ADUC_ParseUpdateType(updateType, &updateTypeName, &updateTypeVersion));
CHECK_THAT(updateTypeName, Equals("microsoft/apt"));
CHECK(updateTypeVersion == 4294967294);
free(updateTypeName);
}

SECTION("Positive UINT MAX")
Expand All @@ -301,6 +310,7 @@ TEST_CASE("ADUC_ParseUpdateType and atoui")
char* updateTypeName = nullptr;
unsigned int updateTypeVersion;
CHECK(ADUC_ParseUpdateType(updateType, &updateTypeName, &updateTypeVersion));
free(updateTypeName);
}

SECTION("Positive Larger Than UINT MAX")
Expand All @@ -309,6 +319,7 @@ TEST_CASE("ADUC_ParseUpdateType and atoui")
char* updateTypeName = nullptr;
unsigned int updateTypeVersion;
CHECK(!ADUC_ParseUpdateType(updateType, &updateTypeName, &updateTypeVersion));
free(updateTypeName);
}

SECTION("Positive ULONG MAX")
Expand All @@ -317,6 +328,7 @@ TEST_CASE("ADUC_ParseUpdateType and atoui")
char* updateTypeName = nullptr;
unsigned int updateTypeVersion;
CHECK(!ADUC_ParseUpdateType(updateType, &updateTypeName, &updateTypeVersion));
free(updateTypeName);
}

SECTION("Version contains space")
Expand All @@ -325,6 +337,7 @@ TEST_CASE("ADUC_ParseUpdateType and atoui")
char* updateTypeName = nullptr;
unsigned int updateTypeVersion;
CHECK(!ADUC_ParseUpdateType(updateType, &updateTypeName, &updateTypeVersion));
free(updateTypeName);
}

SECTION("Decimal version")
Expand All @@ -333,6 +346,7 @@ TEST_CASE("ADUC_ParseUpdateType and atoui")
char* updateTypeName = nullptr;
unsigned int updateTypeVersion;
CHECK(!ADUC_ParseUpdateType(updateType, &updateTypeName, &updateTypeVersion));
free(updateTypeName);
}
}

Expand Down

0 comments on commit 2c264e4

Please sign in to comment.