liftEitherCFree :: (CEither -> IO ()) -- ^ A custom function to free the CEither
                -> (Ptr () -> IO a)   -- ^ A function to transform the pointer contained in the C structure
                -> IO CEither         -- ^ An action returning the structure, typically a call to C
                -> IO (Either SimpleSSHError a)
liftEitherCFree customFree builder action = do
  eitherC   <- action
  checkLeft <- isLeftC eitherC
  res <- if checkLeft == 0
    then Right <$> getValue eitherC builder
    else Left  <$> getError eitherC
  customFree eitherC
  return res

-- | Version of 'liftEitherCFree' using the normal 'free'.
liftEitherCFree :: (CEither -> IO ()) -- ^ A custom function to free the CEither
                -> (Ptr () -> IO a)   -- ^ A function to transform the pointer contained in the C structure
                -> IO CEither         -- ^ An action returning the structure, typically a call to C
                -> IO (Either SimpleSSHError a)
liftEitherCFree customFree builder action = do
  eitherC   <- action
  checkLeft <- isLeftC eitherC
  res <- if checkLeft == 0
    then Right <$> getValue eitherC builder
    else Left  <$> getError eitherC
  customFree eitherC
  return res

-- | Version of 'liftEitherCFree' using the normal 'free'.
liftEitherCFree customFree builder action = do
  eitherC   <- action
  checkLeft <- isLeftC eitherC
  res <- if checkLeft == 0
    then Right <$> getValue eitherC builder
    else Left  <$> getError eitherC
  customFree eitherC
  return res

-- | Version of 'liftEitherCFree' using the normal 'free'.