Skip to content

Commit

Permalink
🔥HOTFIX : Prevent dangling pointer
Browse files Browse the repository at this point in the history
Previously, COption destructor attempted to free the memory that is already freed. After all, the source code broke the rule of three, and it is fixed by Defining Cleanup function in COption, within this function, checking for null pointers guards against dangling pointers
  • Loading branch information
hyeonwoody committed Jan 17, 2024
1 parent 40f3724 commit 1fc3f2a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Beyond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ int CMain::ParseParam() {
}

free(this->option.optionList);
this->option.optionList = nullptr;
free(this->option.flagList);
this->option.flagList = nullptr;
return 0;
}

Expand Down
9 changes: 9 additions & 0 deletions Option.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ struct SMapping{

class COption
{
private:
void Cleanup(){
if (optionList)
free(optionList);
if (flagList)
free(flagList);
}

public:
public:
int m_argc;
Expand Down Expand Up @@ -63,6 +71,7 @@ class COption

}
~COption(){
Cleanup();
}

bool add_option_insert (SMapping* currentMapping);
Expand Down
1 change: 1 addition & 0 deletions feature/VideoCut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ int CJob::CVideoCut::proceed (CJob* pJob, SOptionGroup* optionGroup, SFlagGroup*
input.fileName = path + clipList[i]->source;
if ((ret = avformat_open_input(&input.formatContext, input.fileName.c_str(), NULL, NULL)) < 0){
std::cout<<"Could not open source file : "<<input.fileName<<std::endl;
continue;
}
output.fileName = (path + folderName) + "/" + clipList[i]->name+".mp4";
if ((ret = avformat_find_stream_info(input.formatContext, 0)) < 0){
Expand Down

0 comments on commit 1fc3f2a

Please sign in to comment.