Memory leak fixes in Python default argument handling

This commit is contained in:
William S Fulton 2017-06-23 14:19:12 +01:00
commit a2267a8152

View file

@ -1874,6 +1874,7 @@ public:
String *new_value = convertValue(value, Getattr(p, "type")); String *new_value = convertValue(value, Getattr(p, "type"));
if (new_value) if (new_value)
Printf(doc, "=%s", new_value); Printf(doc, "=%s", new_value);
Delete(new_value);
} }
Delete(type_str); Delete(type_str);
Delete(made_name); Delete(made_name);
@ -2090,7 +2091,7 @@ public:
Delete(octal_string); Delete(octal_string);
return result; return result;
} }
result = *end == '\0' ? v : NewStringWithSize(s, (int) (end - s)); result = *end == '\0' ? Copy(v) : NewStringWithSize(s, (int) (end - s));
return result; return result;
} }
@ -2132,7 +2133,7 @@ public:
// Avoid unnecessary string allocation in the common case when we don't // Avoid unnecessary string allocation in the common case when we don't
// need to remove any suffix. // need to remove any suffix.
return *end == '\0' ? v : NewStringWithSize(s, (int)(end - s)); return *end == '\0' ? Copy(v) : NewStringWithSize(s, (int)(end - s));
} }
return NIL; return NIL;
@ -2167,7 +2168,7 @@ public:
Node *lookup = Swig_symbol_clookup(v, 0); Node *lookup = Swig_symbol_clookup(v, 0);
if (lookup) { if (lookup) {
if (Cmp(Getattr(lookup, "nodeType"), "enumitem") == 0) if (Cmp(Getattr(lookup, "nodeType"), "enumitem") == 0)
result = Getattr(lookup, "sym:name"); result = Copy(Getattr(lookup, "sym:name"));
} }
} }
} }
@ -2214,10 +2215,12 @@ public:
if (Getattr(p, "tmap:default")) if (Getattr(p, "tmap:default"))
return false; return false;
if (String *value = Getattr(p, "value")) { String *value = Getattr(p, "value");
String *type = Getattr(p, "type"); if (value) {
if (!convertValue(value, type)) String *convertedValue = convertValue(value, Getattr(p, "type"));
if (!convertedValue)
return false; return false;
Delete(convertedValue);
} }
} }