Changeset 13075 in project


Ignore:
Timestamp:
01/24/09 17:24:36 (11 years ago)
Author:
Alaric Snell-Pym
Message:

Now without memory leaks, and with NULL-return checking!

Location:
release/3/lzma/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/3/lzma/trunk/lzma.scm

    r13063 r13075  
    1212(define _compress (foreign-lambda* c-pointer ((blob inblob) (int inlen))
    1313   "C_return (lzma_compress(inblob, inlen, &lzma_return_buffer_len));"))
     14(define _free (foreign-lambda void "lzma_free" c-pointer))
    1415
    1516(define (lzma:decompress inblob)
    16    (let* ((ptr (_decompress inblob (blob-size inblob)))
    17           (outblob (make-blob lzma-return-buffer-len)))
    18       (begin
    19          (move-memory! ptr outblob lzma-return-buffer-len)
    20          outblob)))
     17   (let ((ptr (_decompress inblob (blob-size inblob))))
     18      (if (null-pointer? ptr)
     19         #f
     20         (let ((outblob (make-blob lzma-return-buffer-len)))
     21            (begin
     22               (move-memory! ptr outblob lzma-return-buffer-len)
     23               (_free ptr)
     24               outblob)))))
    2125
    2226(define (lzma:compress inblob)
    23    (let* ((ptr (_compress inblob (blob-size inblob)))
    24           (outblob (make-blob lzma-return-buffer-len)))
    25       (begin
    26          (move-memory! ptr outblob lzma-return-buffer-len)
    27          outblob)))
     27   (let ((ptr (_compress inblob (blob-size inblob))))
     28      (if (null-pointer? ptr)
     29         #f
     30         (let ((outblob (make-blob lzma-return-buffer-len)))
     31            (begin
     32               (move-memory! ptr outblob lzma-return-buffer-len)
     33               (_free ptr)
     34               outblob)))))
  • release/3/lzma/trunk/tests/run.scm

    r13063 r13075  
    11(load "../lzma")
    22
    3 (define test-string (with-input-from-file "lzma.so" (lambda () (read-string))))
     3(define test-string (with-input-from-file "../lzma.so" (lambda () (read-string))))
    44
    55(define test-blob (string->blob test-string))
Note: See TracChangeset for help on using the changeset viewer.