[darcs-users] darcs patch: fix memory leak in check/repair

Eric Kow kowey at darcs.net
Fri Apr 10 22:27:07 UTC 2009


Hi Petr,

On Mon, Apr 06, 2009 at 02:14:56 +0000, E.Y.Kow at brighton.ac.uk wrote:
> Sat Mar 21 04:22:37 GMT 2009  David Roundy <droundy at darcs.net>
>   * fix memory leak in check/repair

Could you have a look at this when you have a chance?

One thing to consider also is if this buys us any simplification to the
check/repair code.

Thanks!

fix memory leak in check/repair
-------------------------------
> David Roundy <droundy at darcs.net>**20090321042237
>  Ignore-this: 21a3f1766aafde76f4a6d471dc8ce13450930947
> ] hunk ./src/Darcs/Repository/HashedRepo.hs 211
>  write_and_read_patch :: RepoPatch p => Cache -> Compression -> PatchInfoAnd p C(x y)
>                       -> IO (PatchInfoAnd p C(x y))
>  write_and_read_patch c compr p = do (i,h) <- write_patch_if_necesary c compr p
> -                                    Sealed x <- createHashed h (parse i)
> -                                    return $ patchInfoAndPatch i $ unsafeCoerceP x
> -    where parse i h = do debugMessage ("Reading patch file: "++ show (human_friendly i))
> +                                    unsafeInterleaveIO $ readp h i
> +    where parse i h = do debugMessage ("Rereading patch file: "++ show (human_friendly i))
>                           (fn,ps) <- fetchFileUsingCache c HashedPatchesDir h
>                           case readPatch ps of
>                             Just (x,_) -> return x
> hunk ./src/Darcs/Repository/HashedRepo.hs 219
>                             Nothing -> fail $ unlines ["Couldn't parse patch file "++fn,
>                                                        "which is",
>                                                        renderString $ human_friendly i]
> +          readp h i = do Sealed x <- createHashed h (parse i)
> +                         return $ patchInfoAndPatch i $ unsafeCoerceP x
>  
>  write_tentative_inventory :: RepoPatch p => Cache -> Compression -> PatchSet p C(x) -> IO ()
>  write_tentative_inventory c compr = write_either_inventory c compr "tentative_hashed_inventory"
> hunk ./src/Darcs/Repository/HashedRepo.hs 266
>  write_patch_if_necesary :: RepoPatch p => Cache -> Compression
>                          -> PatchInfoAnd p C(x y) -> IO (PatchInfo, String)
>  write_patch_if_necesary c compr hp =
> -    case extractHash hp of
> -    Right h -> return (info hp, h)
> -    Left p -> fmap (\h -> (info hp, h)) $ writeHashFile c compr HashedPatchesDir $ showPatch p
> +    seq infohp $ case extractHash hp of
> +                   Right h -> return (infohp, h)
> +                   Left p -> (\h -> (infohp, h)) `fmap`
> +                             writeHashFile c compr HashedPatchesDir (showPatch p)
> +    where infohp = info hp
>  
>  pihash :: (PatchInfo,String) -> Doc
>  pihash (pinf,hash) = showPatchInfo pinf $$ text ("hash: " ++ hash ++ "\n")
> 

-- 
Eric Kow <http://www.nltg.brighton.ac.uk/home/Eric.Kow>
PGP Key ID: 08AC04F9
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/darcs-users/attachments/20090410/461f288a/attachment.pgp>


More information about the darcs-users mailing list