From b9e418625581f4c56a7b47f7e29f541618d5e2fd Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 10 Aug 2010 15:41:16 +0200 Subject: [PATCH] Fix leak in parse_facet + compilation on Windows yaz_pqf_destroy not called. Constructs such as buffer[length] not supported on Visual Studio 2008. --- src/pquery.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/pquery.c b/src/pquery.c index 3004c24..65dcdd1 100644 --- a/src/pquery.c +++ b/src/pquery.c @@ -826,24 +826,20 @@ Z_AttributeList *yaz_pqf_scan_attribute_list(YAZ_PQF_Parser p, ODR o, static Z_FacetField* parse_facet(ODR odr, const char *facet, int length) { YAZ_PQF_Parser pqf_parser = yaz_pqf_create(); - char buffer[length+1]; + char *buffer = odr_strdupn(odr, facet, length); Odr_oid *attributeSetId; - Z_FacetField *facet_field; - Z_AttributeList *attribute_list; - memcpy(buffer, facet, length); - buffer[length] = '\0'; - attribute_list = yaz_pqf_scan_attribute_list(pqf_parser, odr, &attributeSetId, buffer); - - if (!attribute_list) { - printf("Invalid facet definition: %s", facet); - return 0; + Z_FacetField *facet_field = 0; + Z_AttributeList *attribute_list = + yaz_pqf_scan_attribute_list(pqf_parser, odr, &attributeSetId, buffer); + + if (attribute_list) + { + facet_field = odr_malloc(odr, sizeof(*facet_field)); + facet_field->attributes = attribute_list; + facet_field->num_terms = 0; + facet_field->terms = 0; } - facet_field = odr_malloc(odr, sizeof(*facet_field)); - facet_field->attributes = attribute_list; - facet_field->num_terms = 0; - facet_field->terms = 0; - //debug_add_facet_term(odr, facet_field); - + yaz_pqf_destroy(pqf_parser); return facet_field; } -- 1.7.10.4