Skip to content

Commit

Permalink
add Qiniu_RSF_ListRet_Cleanup() to free Qiniu_RSF_ListRet (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
bachue authored Aug 30, 2023
1 parent e8caec8 commit 105c067
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
13 changes: 3 additions & 10 deletions examples/rsf_list_bucket.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int main(int argc, char **argv) {

char **commonPrefixes = NULL;
Qiniu_RSF_ListItem *items = NULL;

Qiniu_Client_InitMacAuth(&client, 1024, &mac);

do {
Expand Down Expand Up @@ -75,17 +75,10 @@ int main(int argc, char **argv) {
}

//free
if (listRet.commonPrefixes != NULL) {
Qiniu_Free(listRet.commonPrefixes);
}
if (listRet.items != NULL) {
Qiniu_Free(listRet.items);
}

Qiniu_Zero(listRet);
Qiniu_RSF_ListRet_Cleanup(&listRet);
}

} while (!str_empty(nextMarker));

Qiniu_Client_Cleanup(&client);
}
9 changes: 2 additions & 7 deletions examples/rsf_list_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,8 @@ int main(int argc, char **argv) {
}

//free
if (listRet.commonPrefixes != NULL) {
Qiniu_Free(listRet.commonPrefixes);
}
if (listRet.items != NULL) {
Qiniu_Free(listRet.items);
}
Qiniu_RSF_ListRet_Cleanup(&listRet);
}

Qiniu_Client_Cleanup(&client);
}
}
1 change: 1 addition & 0 deletions gtests/rsf_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ TEST(IntegrationTest, TestRsfListFiles)
printf("%s\n", listRet.items[i].key);
}
totalCount += listRet.itemsCount;
Qiniu_RSF_ListRet_Cleanup(&listRet);
} while (listRet.marker != NULL);
EXPECT_GT(totalCount, 0);

Expand Down
14 changes: 14 additions & 0 deletions qiniu/rsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,17 @@ Qiniu_Error Qiniu_RSF_ListFiles(Qiniu_Client *self, Qiniu_RSF_ListRet *ret, cons

return err;
}

void Qiniu_RSF_ListRet_Cleanup(Qiniu_RSF_ListRet *self)
{
if (self->items != NULL)
{
Qiniu_FreeV2((void **)&self->items);
self->itemsCount = 0;
}
if (self->commonPrefixes != NULL)
{
Qiniu_FreeV2((void **)&self->commonPrefixes);
self->commonPrefixesCount = 0;
}
}
1 change: 1 addition & 0 deletions qiniu/rsf.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extern "C"
QINIU_DLLAPI extern Qiniu_Error Qiniu_RSF_ListFiles(Qiniu_Client *self, Qiniu_RSF_ListRet *ret, const char *bucket,
const char *prefix, const char *delimiter, const char *marker,
int limit);
QINIU_DLLAPI extern void Qiniu_RSF_ListRet_Cleanup(Qiniu_RSF_ListRet *self);
#pragma pack()

#ifdef __cplusplus
Expand Down

0 comments on commit 105c067

Please sign in to comment.