Skip to content

Fix free calls #44

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

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/Database/LevelDB/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@
)
where

import Control.Applicative ((<$>))

Check warning on line 62 in src/Database/LevelDB/Base.hs

View workflow job for this annotation

GitHub Actions / linux (9.10.1)

The import of ‘Control.Applicative’ is redundant

Check warning on line 62 in src/Database/LevelDB/Base.hs

View workflow job for this annotation

GitHub Actions / linux (9.8.2)

The import of ‘Control.Applicative’ is redundant

Check warning on line 62 in src/Database/LevelDB/Base.hs

View workflow job for this annotation

GitHub Actions / linux (9.6.5)

The import of ‘Control.Applicative’ is redundant

Check warning on line 62 in src/Database/LevelDB/Base.hs

View workflow job for this annotation

GitHub Actions / linux (latest)

The import of ‘Control.Applicative’ is redundant
import Control.Monad (liftM, void)
import Control.Monad.Catch
import Control.Monad.IO.Class (MonadIO (liftIO))
import Data.ByteString (ByteString)
import Data.ByteString.Internal (ByteString (..))
import Data.IORef
import Foreign hiding (void)
import Foreign hiding (free, void)
import Foreign.C.String (withCString)

import Database.LevelDB.C
Expand Down Expand Up @@ -135,7 +135,7 @@
if val_ptr == nullPtr
then return Nothing
else do res <- Just <$> BS.packCString val_ptr
free val_ptr
c_leveldb_free val_ptr
return res
where
prop (NumFilesAtLevel i) = "leveldb.num-files-at-level" ++ show i
Expand Down Expand Up @@ -178,7 +178,7 @@
from_ptrs flen_ptrs
to_ptrs tlen_ptrs
size_ptrs
liftM head $ peekArray 1 size_ptrs >>= mapM toInt64

Check warning on line 181 in src/Database/LevelDB/Base.hs

View workflow job for this annotation

GitHub Actions / linux (9.10.1)

In the use of ‘head’

Check warning on line 181 in src/Database/LevelDB/Base.hs

View workflow job for this annotation

GitHub Actions / linux (9.8.2)

In the use of ‘head’

where
toInt64 = return . fromIntegral
Expand Down Expand Up @@ -214,7 +214,7 @@
then return Nothing
else do
res' <- Just <$> BS.packCStringLen (val_ptr, cSizeToInt vlen)
free val_ptr
c_leveldb_free val_ptr
return res'

-- | Delete a key/value pair.
Expand Down
13 changes: 10 additions & 3 deletions src/Database/LevelDB/C.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
module Database.LevelDB.C where

import Foreign
import Foreign.C.Types
import Foreign.C.String
import Foreign.C.Types

#include <leveldb/c.h>

Expand Down Expand Up @@ -354,11 +354,18 @@ foreign import ccall safe "leveldb/c.h leveldb_cache_create_lru"
foreign import ccall safe "leveldb/c.h leveldb_cache_destroy"
c_leveldb_cache_destroy :: CachePtr -> IO ()


--
-- Version
-- Utility
--

-- Calls free(ptr).
-- REQUIRES: ptr was malloc()-ed and returned by one of the routines
-- in this file. Note that in certain cases (typically on Windows), you
-- may need to call this routine instead of free(ptr) to dispose of
-- malloc()-ed memory returned by this library. */
foreign import ccall safe "leveldb/c.h leveldb_free"
c_leveldb_free :: Ptr a -> IO ()

foreign import ccall unsafe "leveldb/c.h leveldb_major_version"
c_leveldb_major_version :: IO CInt

Expand Down
Loading