Skip to content

Commit

Permalink
Fix memory leak in 'cowl_has_key_axiom'
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanoBilenchi committed Dec 4, 2024
1 parent 540e04a commit 0c56dcb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ repos:
- id: mixed-line-ending
- id: end-of-file-fixer
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.3
rev: v19.1.4
hooks:
- id: clang-format
2 changes: 2 additions & 0 deletions data/test_import.owl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ EquivalentObjectProperties(:ObjectPropertyA ObjectInverseOf(:ObjectPropertyB))

SubClassOf(:ClassA ObjectAllValuesFrom(:ObjectPropertyA owl:Thing))
SubClassOf(:ClassA ObjectSomeValuesFrom(:ObjectPropertyA owl:Thing))
HasKey(:ClassA (:hasKeyProperty_2) ())
HasKey(:ClassA () (:hasKeyProperty_1))


############################
Expand Down
15 changes: 4 additions & 11 deletions include/cowl_has_key_axiom.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include "cowl_attrs.h"
#include "cowl_impl.h"
#include "cowl_macros.h"
#include "cowl_object_type.h"
#include "cowl_vector.h"

COWL_BEGIN_DECLS

Expand Down Expand Up @@ -46,20 +44,15 @@ cowl_struct_decl(CowlHasKeyAxiom);
* Returns a 'has key' axiom.
*
* @param cls_exp The class expression, instances of which this axiom acts as the key for.
* @param obj_props Object property expressions that make up the key.
* @param data_props Data property expressions that make up the key.
* @param obj_props @type{optional} Object property expressions that make up the key.
* @param data_props @type{optional} Data property expressions that make up the key.
* @param annot @type{optional} The annotations.
* @return Axiom, or NULL on error.
*/
COWL_API
COWL_RETAINED
COWL_INLINE
CowlHasKeyAxiom *cowl_has_key_axiom(CowlAnyClsExp *cls_exp, CowlVector *obj_props,
CowlVector *data_props, CowlVector *annot) {
if (!obj_props) obj_props = cowl_vector_empty();
if (!data_props) data_props = cowl_vector_empty();
return (CowlHasKeyAxiom *)cowl_get_impl_3_annot(COWL_OT_A_HAS_KEY, cls_exp, obj_props,
data_props, annot);
}
CowlVector *data_props, CowlVector *annot);

/**
* Gets the class expression, instances of which this axiom acts as the key for.
Expand Down
2 changes: 1 addition & 1 deletion include/cowl_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ cowl_struct_decl(CowlVector);
*/
COWL_API
COWL_RETAINED
CowlVector *cowl_vector(UVec(CowlObjectPtr) *vec);
CowlVector *cowl_vector(UVec(CowlObjectPtr) *data);

/**
* Returns a vector with no elements.
Expand Down
26 changes: 26 additions & 0 deletions src/cowl_has_key_axiom.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @author Ivano Bilenchi
*
* @copyright Copyright (c) 2024 SisInf Lab, Polytechnic University of Bari
* @copyright <http://swot.sisinflab.poliba.it>
* @copyright SPDX-License-Identifier: EPL-2.0
*
* @file
*/

#include "cowl_has_key_axiom.h"
#include "cowl_any.h"
#include "cowl_impl.h"
#include "cowl_object.h"
#include "cowl_object_type.h"
#include "cowl_vector.h"

CowlHasKeyAxiom *cowl_has_key_axiom(CowlAnyClsExp *cls_exp, CowlVector *obj_props,
CowlVector *data_props, CowlVector *annot) {
obj_props = obj_props ? cowl_retain(obj_props) : cowl_vector_empty();
data_props = data_props ? cowl_retain(data_props) : cowl_vector_empty();
CowlAny *ret = cowl_get_impl_3_annot(COWL_OT_A_HAS_KEY, cls_exp, obj_props, data_props, annot);
cowl_release(obj_props);
cowl_release(data_props);
return ret;
}
4 changes: 2 additions & 2 deletions test/tests/cowl_ontology_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
static CowlOntology *onto = NULL;

static ulib_uint const test_onto_imports_count = 1;
static ulib_uint const test_onto_axiom_count = 571;
static ulib_uint const test_onto_axiom_count = 573;

static ulib_uint const test_primitives_count[] = { 106, 48, 72, 27, 18, 1, 46, 12 };
static ulib_uint const test_primitive_axiom_count[] = { 16, 4, 4, 2, 2, 1, 2, 8 };
Expand Down Expand Up @@ -66,7 +66,7 @@ static void axiom_counts_by_type_init(void) {
axiom_counts_by_type[COWL_AT_FUNC_DATA_PROP] = 1;
axiom_counts_by_type[COWL_AT_DATA_PROP_DOMAIN] = 66;
axiom_counts_by_type[COWL_AT_DATA_PROP_RANGE] = 66;
axiom_counts_by_type[COWL_AT_HAS_KEY] = 1;
axiom_counts_by_type[COWL_AT_HAS_KEY] = 3;
axiom_counts_by_type[COWL_AT_ANNOT_ASSERT] = 19;
axiom_counts_by_type[COWL_AT_SUB_ANNOT_PROP] = 1;
axiom_counts_by_type[COWL_AT_ANNOT_PROP_DOMAIN] = 1;
Expand Down

0 comments on commit 0c56dcb

Please sign in to comment.