diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-12-28 21:49:02 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2024-12-28 21:57:01 +0530 |
| commit | 9b5c8368daa97a5b58a378d9c4eab66ebb018cb0 (patch) | |
| tree | 9faec7fbb2da551e02c819cabfedf670b6fc854a /src | |
| parent | d000cbb52821dc33c5d2f3d676dc6efa54f3b25f (diff) | |
| download | chelleport-9b5c8368daa97a5b58a378d9c4eab66ebb018cb0.tar.gz chelleport-9b5c8368daa97a5b58a378d9c4eab66ebb018cb0.zip | |
Fix memory leak issue with c++ interop
Diffstat (limited to 'src')
| -rw-r--r-- | src/Chelleport/OCR.hs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/Chelleport/OCR.hs b/src/Chelleport/OCR.hs index 64c69e5..43ab34d 100644 --- a/src/Chelleport/OCR.hs +++ b/src/Chelleport/OCR.hs @@ -5,7 +5,7 @@ import Control.Concurrent (threadDelay) import Control.Monad.IO.Class (MonadIO (liftIO)) import Control.Monad.RWS (MonadReader (ask)) import qualified Data.ByteString as BS -import Foreign (Bits (shiftR), Ptr, Storable (peek, pokeByteOff), alloca, allocaBytes, peekArray, (.&.)) +import Foreign (Bits (shiftR), Ptr, Storable (peek, pokeByteOff), alloca, allocaBytes, free, peekArray, (.&.)) import Foreign.C (CInt, CString, newCString) import GHC.IO.Handle.FD (withFile) import GHC.IO.IOMode (IOMode (WriteMode)) @@ -31,7 +31,6 @@ instance (MonadIO m) => MonadOCR (AppM m) where pure path getWordsInImage filePath = liftIO $ do - -- result `seq` pure result -- Strict eval findWordCoordinates filePath <* removeFile filePath findWordCoordinates :: String -> IO [OCRMatch] @@ -40,7 +39,9 @@ findWordCoordinates imgPath = alloca $ \sizePtr -> do arrayPtr <- c_getAllWordCoordinates imgPathC sizePtr size <- peek sizePtr - peekArray (fromIntegral size) arrayPtr + result <- peekArray (fromIntegral size) arrayPtr + free arrayPtr + pure result createTemporaryScreenshot :: DrawContext -> (CInt, CInt) -> (CInt, CInt) -> IO String createTemporaryScreenshot ctx offset size = do |
