Commit 1ec68386 authored by Vikram Narayanan's avatar Vikram Narayanan
Browse files

idl/ccst: Fix memory leak in indentation



Indentation function is being called from many places to ensure
proper spacing in the generated file. However, this malloc'ed
memory is never freed. Switch to a version using switch..case
which does not use memory

Signed-off-by: Vikram Narayanan's avatarVikram Narayanan <vikram186@gmail.com>
parent 1ab874aa
......@@ -2037,8 +2037,20 @@ void CCSTReturn::write(FILE *f, int indent)
}
}
// FIXME: How to handle this efficiently for multiple
// levels? Surely we cannot waste memory by allocating.
// May be some macro magic?
const char* indentation(int level)
{
switch (level) {
case 0:
return " ";
case 1:
return "\t";
case 2:
return "\t\t";
}
#if 0
int length = level*INDENT;
char *spacing = (char*) malloc(sizeof(char)*(length+1));
......@@ -2051,4 +2063,5 @@ const char* indentation(int level)
}
strncpy(spacing, total.str().c_str(), length+1);
return spacing;
#endif
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment