Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution to Memory leaks by interning external strings #24 per @sletner #234

Closed
wants to merge 2 commits into from
Closed
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
15 changes: 15 additions & 0 deletions headers.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

;;; The following code is for treating headers which exist in the keyword package as keywords, otherwise they will be treated as strings. This code will override the chunga code which by default interns every header to be a keyword

(in-package :chunga)

(defvar *intern-unsafely* NIL)

(defun as-keyword (string &key (destructivep t))
"Checks if the string STRING is found as a keyword and if it is, returns the keyword, otherwise it returns a string. Note that this is obviously not congruent to the name of the function, it is meant to be an override to the default behavior to avoid memory leaks in Hunchentoot"
(or (find-symbol (string-upcase string) (find-package "KEYWORD"))
(if *intern-unsafely*
(make-keyword string destructivep)
string)))

;;; End of Headers as Keywords Representation Code

(in-package :hunchentoot)

(defgeneric write-header-line (key value stream)
Expand Down