forked from xapi-project/xen-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove possible systematic leak in Imperative priority queue
The queue is implemented with an Array larger than the content. Instead of copying an initial value taken from first insert or potentially later when the Array is expanded provide a "default" value to use as a filler. This allows to provide a value not having references to external object so not extending their lifetime in an unpredictable way. Signed-off-by: Frediano Ziglio <[email protected]>
- Loading branch information
Showing
5 changed files
with
89 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
(* | ||
* Copyright (C) 2024 Cloud Software Group | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation; version 2.1 only. with the special | ||
* exception on linking described in file LICENSE. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
*) | ||
|
||
type 'a event = {ev: 'a; time: Mtime.t} | ||
|
||
type 'a t | ||
|
||
exception EmptyHeap | ||
|
||
val create : int -> 'a -> 'a t | ||
(** [create n default] creates an empty Imperative priority queue. | ||
The queue initially is initialized to store [n] elements. | ||
The queue will expand beyond [n] automatically if needed. | ||
[default] value will the used to fill unused data. *) | ||
|
||
val is_empty : 'a t -> bool | ||
(** Check if the queue is empty *) | ||
|
||
val add : 'a t -> 'a event -> unit | ||
(** Add an event to the queue *) | ||
|
||
val remove : 'a t -> int -> unit | ||
(** Remove an event from the queue passing the index. | ||
@raise EmptyHeap if the queue is empty. | ||
@raise Invalid_argument if the index is invalid. *) | ||
|
||
val find_p : 'a t -> ('a -> bool) -> int | ||
(** Find the index of an event which matches a given condition | ||
or -1 if not found *) | ||
|
||
val find : 'a t -> 'a -> int | ||
(** Find the index of an event which matches a given event | ||
or -1 if not found *) | ||
|
||
val maximum : 'a t -> 'a event | ||
(** Return a copy of the event with the next time. | ||
@raise EmptyHeap if the queue is empty. *) | ||
|
||
val pop_maximum : 'a t -> 'a event | ||
(** Return and remove the event with the next time. | ||
@raise EmptyHeap if the queue is empty. *) | ||
|
||
val iter : ('a event -> unit) -> 'a t -> unit | ||
(** Iterate given function on the list of events in the queue *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters