aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/PIC16/PIC16.h
diff options
context:
space:
mode:
authorSanjiv Gupta <sanjiv.gupta@microchip.com>2010-04-07 03:36:01 +0000
committerSanjiv Gupta <sanjiv.gupta@microchip.com>2010-04-07 03:36:01 +0000
commitd49baefaad45715774f6409b76274dc62f33f8c0 (patch)
tree69d517e1af6241932603cdf5dbc5ade9bdf9931e /lib/Target/PIC16/PIC16.h
parentb1fb4497b0a468a0cb75958ee8ddabf409a12d87 (diff)
Fix memory leaks for external symbol name strings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100601 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/PIC16/PIC16.h')
-rw-r--r--lib/Target/PIC16/PIC16.h36
1 files changed, 27 insertions, 9 deletions
diff --git a/lib/Target/PIC16/PIC16.h b/lib/Target/PIC16/PIC16.h
index 8d067de676..cee55f4f26 100644
--- a/lib/Target/PIC16/PIC16.h
+++ b/lib/Target/PIC16/PIC16.h
@@ -21,6 +21,7 @@
#include <sstream>
#include <cstring>
#include <string>
+#include <vector>
namespace llvm {
class PIC16TargetMachine;
@@ -52,17 +53,34 @@ namespace PIC16CC {
UDATA_SHR
};
+ class ESNames {
+ std::vector<char*> stk;
+ ESNames() {}
+ public:
+ ~ESNames() {
+ std::vector<char*>::iterator it = stk.end();
+ it--;
+ while(stk.end() != stk.begin())
+ {
+ char* p = *it;
+ delete [] p;
+ it--;
+ stk.pop_back();
+ }
+ }
- // External symbol names require memory to live till the program end.
- // So we have to allocate it and keep.
- // FIXME: Don't leak the allocated strings.
- inline static const char *createESName (const std::string &name) {
- char *tmpName = new char[name.size() + 1];
- memcpy(tmpName, name.c_str(), name.size() + 1);
- return tmpName;
- }
-
+ // External symbol names require memory to live till the program end.
+ // So we have to allocate it and keep. Push all such allocations into a
+ // vector so that they get freed up on termination.
+ inline static const char *createESName (const std::string &name) {
+ static ESNames esn;
+ char *tmpName = new char[name.size() + 1];
+ memcpy(tmpName, name.c_str(), name.size() + 1);
+ esn.stk.push_back(tmpName);
+ return tmpName;
+ }
+ };
inline static const char *PIC16CondCodeToString(PIC16CC::CondCodes CC) {
switch (CC) {