code: def run_debug_memory_pool(pool_factory, env_value):
      """
      Run a piece of code making an invalid memory write with the
      ARROW_DEBUG_MEMORY_POOL environment variable set to a specific value.
      """
      code = f"""if 1:
          import ctypes
          import pyarrow as pa
          # ARROW-16873: some Python installs enable faulthandler by default,
          # which could dump a spurious stack trace if the following crashes
          import faulthandler
          faulthandler.disable()
  
          pool = pa.{pool_factory}()
          buf = pa.allocate_buffer(64, memory_pool=pool)
  
          # Write memory out of bounds
          ptr = ctypes.cast(buf.address, ctypes.POINTER(ctypes.c_ubyte))
          ptr[64] = 0
  
          del buf
          """
      env = dict(os.environ)
      env["ARROW_DEBUG_MEMORY_POOL"] = env_value
      res = subprocess.run(
          [sys.executable, "-c", code],
          env=env,
          universal_newlines=True,
          stderr=subprocess.PIPE,
      )
      print(res.stderr, file=sys.stderr)
      return res
  
imports: import contextlib
  import os
  import signal
  import subprocess
  import sys
  import weakref
  import pyarrow
  import pytest
label_desc: Use image node_id 14 for calling a global function with example usage: run_debug_memory_pool(pool_factory, env_value) and returns: res