-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add memory limit to prevent converter to AST get OOM (#8351)
- Loading branch information
1 parent
3a914af
commit 3caa09f
Showing
7 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "limiting_allocator.h" | ||
|
||
#include <util/memory/pool.h> | ||
#include <util/generic/yexception.h> | ||
|
||
namespace { | ||
class TLimitingAllocator : public IAllocator { | ||
public: | ||
TLimitingAllocator(size_t limit, IAllocator* allocator) : Alloc_(allocator), Limit_(limit) {}; | ||
TBlock Allocate(size_t len) override final { | ||
if (Allocated_ + len > Limit_) { | ||
throw std::runtime_error("Out of memory"); | ||
} | ||
Allocated_ += len; | ||
return Alloc_->Allocate(len); | ||
} | ||
|
||
void Release(const TBlock& block) override final { | ||
Y_ENSURE(Allocated_ >= block.Len); | ||
Allocated_ -= block.Len; | ||
Alloc_->Release(block); | ||
} | ||
|
||
private: | ||
IAllocator* Alloc_; | ||
size_t Allocated_ = 0; | ||
const size_t Limit_; | ||
}; | ||
} | ||
|
||
namespace NYql { | ||
std::unique_ptr<IAllocator> MakeLimitingAllocator(size_t limit, IAllocator* underlying) { | ||
return std::make_unique<TLimitingAllocator>(limit, underlying); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include <util/memory/pool.h> | ||
#include <memory> | ||
|
||
namespace NYql { | ||
std::unique_ptr<IAllocator> MakeLimitingAllocator(size_t limit, IAllocator* underlying); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters