summaryrefslogtreecommitdiff
path: root/src/3rdparty/squirrel
diff options
context:
space:
mode:
authorLoïc Guilloux <glx22@users.noreply.github.com>2021-10-02 15:13:58 +0200
committerGitHub <noreply@github.com>2021-10-02 15:13:58 +0200
commitccd586a736595c2af09c6f614c11a75b9b3da156 (patch)
tree53e76484dcf7690dc10c3a7cdc1a6df8c3f75e4e /src/3rdparty/squirrel
parent78d66b77325ee7f6af0627ce88ca2e83a8048241 (diff)
downloadopenttd-ccd586a736595c2af09c6f614c11a75b9b3da156.tar.xz
Fix #9588, 140a96b: [Squirrel] Reaching memory limit during script registration could prevent further script detections (#9589)
Also the memory allocation triggering the limit was never freed. And if the exception was thrown in a constructor using placement new, the pre-allocated memory was not freed either.
Diffstat (limited to 'src/3rdparty/squirrel')
-rw-r--r--src/3rdparty/squirrel/squirrel/sqobject.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/3rdparty/squirrel/squirrel/sqobject.h b/src/3rdparty/squirrel/squirrel/sqobject.h
index 129674b5a..77d09301c 100644
--- a/src/3rdparty/squirrel/squirrel/sqobject.h
+++ b/src/3rdparty/squirrel/squirrel/sqobject.h
@@ -62,6 +62,24 @@ struct SQRefCounted
SQUnsignedInteger _uiRef;
struct SQWeakRef *_weakref;
virtual void Release()=0;
+
+ /* Placement new/delete to prevent memory leaks if constructor throws an exception. */
+ inline void *operator new(size_t size, SQRefCounted *place)
+ {
+ place->size = size;
+ return place;
+ }
+
+ inline void operator delete(void *ptr, SQRefCounted *place)
+ {
+ SQ_FREE(ptr, place->size);
+ }
+
+ /* Never used but required. */
+ inline void operator delete(void *ptr) { NOT_REACHED(); }
+
+private:
+ size_t size;
};
struct SQWeakRef : SQRefCounted