diff options
author | Lukas Stockner <lukas.stockner@freenet.de> | 2016-05-08 02:44:01 +0300 |
---|---|---|
committer | Lukas Stockner <lukas.stockner@freenet.de> | 2016-05-08 18:44:03 +0300 |
commit | cbaa25eb88a25852791d4f8b18fb9e9137fea401 (patch) | |
tree | 6c11d0aa36ac2f7aac07868262d38964237d0c10 /intern/cycles/render/tables.cpp | |
parent | 6100c2d262c58c611ccc75a20cca23bf9f245767 (diff) |
Cycles: Fix two small memory leaks and deduplicate table freeing
This commit makes remove_table skip the freeing if the offset is
already set to invalid - or, if it wasn't, set it to invalid after freeing.
That's what the current code was already doing in the Manager classes,
this change allows them to just call remove without the additional code.
Also, two potential memory leaks where new tables were always allocated
without freeing the old ones are fixed.
Reviewers: sergey, dingto, brecht
Differential Revision: https://developer.blender.org/D1974
Diffstat (limited to 'intern/cycles/render/tables.cpp')
-rw-r--r-- | intern/cycles/render/tables.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/intern/cycles/render/tables.cpp b/intern/cycles/render/tables.cpp index cde024cc11c..dfafd99961b 100644 --- a/intern/cycles/render/tables.cpp +++ b/intern/cycles/render/tables.cpp @@ -94,15 +94,21 @@ size_t LookupTables::add_table(DeviceScene *dscene, vector<float>& data) return new_table.offset; } -void LookupTables::remove_table(size_t offset) +void LookupTables::remove_table(size_t *offset) { + if(*offset == TABLE_OFFSET_INVALID) { + /* The table isn't even allocated, so just return here. */ + return; + } + need_update = true; list<Table>::iterator table; for(table = lookup_tables.begin(); table != lookup_tables.end(); table++) { - if(table->offset == offset) { + if(table->offset == *offset) { lookup_tables.erase(table); + *offset = TABLE_OFFSET_INVALID; return; } } |