]> git.tdb.fi Git - libs/datafile.git/blob - source/argumentstore.cpp
Plug a memory leak
[libs/datafile.git] / source / argumentstore.cpp
1 #include "argumentstore.h"
2
3 namespace Msp {
4 namespace DataFile {
5
6 ArgumentStore::ArgumentStore(const StatementInfo &n):
7         info(n),
8         store(new char[info.args_size])
9 {
10         for(unsigned i=0; i<info.key.signature.size(); ++i)
11                 switch(info.key.signature[i])
12                 {
13                 case StringType::signature:
14                         new(store+info.arg_offsets[i]) StringType::Store;
15                         break;
16                 case SymbolType::signature:
17                         new(store+info.arg_offsets[i]) SymbolType::Store;
18                         break;
19                 }
20 }
21
22 ArgumentStore::~ArgumentStore()
23 {
24         for(unsigned i=0; i<info.key.signature.size(); ++i)
25                 switch(info.key.signature[i])
26                 {
27                 case StringType::signature:
28                         reinterpret_cast<StringType::Store *>(store+info.arg_offsets[i])->~basic_string();
29                         break;
30                 case SymbolType::signature:
31                         reinterpret_cast<SymbolType::Store *>(store+info.arg_offsets[i])->~Symbol();
32                         break;
33                 }
34
35         delete[] store;
36 }
37
38 } // namespace DataFile
39 } // namespace Msp