Skip to content
Browse files

(rasqal_literal_set_typed_value): remember string ownership for decimal

  • Loading branch information...
1 parent a76ffab commit 4e51df168469d00a536a664787df8974d15f43a0 @dajobe committed May 10, 2012
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/rasqal_literal.c
View
16 src/rasqal_literal.c
@@ -680,24 +680,32 @@ rasqal_literal_set_typed_value(rasqal_literal* l, rasqal_literal_type type,
if(1) {
size_t slen = 0;
rasqal_xsd_decimal* new_d;
-
+ int own_string = (string != NULL);
+
new_d = rasqal_new_xsd_decimal(l->world);
if(!new_d)
return 1;
- if(!string)
- /* use existing literl decimal object (SHARED) string */
+ if(!own_string)
+ /* use existing literal decimal object (SHARED) string */
string = l->string;
if(rasqal_xsd_decimal_set_string(new_d,
RASQAL_GOOD_CAST(const char*, string))) {
rasqal_free_xsd_decimal(new_d);
+ if(own_string)
+ RASQAL_FREE(char*, string);
return 1;
}
- if(l->value.decimal)
+ if(l->value.decimal) {
rasqal_free_xsd_decimal(l->value.decimal);
+ /* old l->string is now invalid */
+ }
l->value.decimal = new_d;
+ if(own_string)
+ RASQAL_FREE(char*, string);
+
/* l->string is now owned by l->value.decimal and will be freed
* on literal destruction
*/

0 comments on commit 4e51df1

Please sign in to comment.
Something went wrong with that request. Please try again.