Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/output_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ dctool_xml_output_write (dctool_output_t *abstract, dc_parser_t *parser, const u
break;
fprintf (output->ostream, "<extradata key='%s' value='%s' />\n",
str.desc, str.value);
free ((void *) str.value);
}

// Parse the GPS location.
Expand Down
1 change: 1 addition & 0 deletions include/libdivecomputer/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ dc_parser_set_density (dc_parser_t *parser, double density);
dc_status_t
dc_parser_get_datetime (dc_parser_t *parser, dc_datetime_t *datetime);

/* DC_FIELD_STRING values are caller-owned and must be freed after use. */
dc_status_t
dc_parser_get_field (dc_parser_t *parser, dc_field_type_t type, unsigned int flags, void *value);

Expand Down
27 changes: 15 additions & 12 deletions src/field-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,27 @@ dc_status_t dc_field_get_string(dc_field_cache_t *cache, unsigned idx, dc_field_
if (idx < MAXSTRINGS) {
dc_field_string_t *res = cache->strings+idx;
if (res->desc && res->value) {
*value = *res;
value->desc = res->desc;
value->value = strdup(res->value);
if (!value->value)
return DC_STATUS_NOMEMORY;
return DC_STATUS_SUCCESS;
}
}
return DC_STATUS_UNSUPPORTED;
}

void
dc_field_cache_free (dc_field_cache_t *cache)
{
for (unsigned int i = 0; i < MAXSTRINGS; i++) {
free ((char *) cache->strings[i].value);
cache->strings[i].value = NULL;
cache->strings[i].desc = NULL;
}
cache->initialized &= ~(1u << DC_FIELD_STRING);
}


/*
* Use this generic "pick fields from the field cache" helper
Expand Down Expand Up @@ -120,14 +134,3 @@ dc_field_get(dc_field_cache_t *cache, dc_field_type_t type, unsigned int flags,

return DC_STATUS_UNSUPPORTED;
}

void
dc_field_cache_free (dc_field_cache_t *cache)
{
for (unsigned int i = 0; i < MAXSTRINGS; i++) {
free ((char *) cache->strings[i].value);
cache->strings[i].value = NULL;
cache->strings[i].desc = NULL;
}
cache->initialized &= ~(1u << DC_FIELD_STRING);
}