code: func Cleanup() error {
  	context.lock.Lock()
  	defer context.lock.Unlock()
  
  	if !context.initialized {
  		return ErrNotInit
  	}
  
  	log.Debug("Closing libmemif library")
  
  	// Delete all active interfaces.
  	for _, memif := range context.memifs {
  		memif.Close()
  	}
  
  	// Stop the event loop (if supported by C-libmemif).
  	errCode := C.memif_cancel_poll_event()
  	err := getMemifError(int(errCode))
  	if err == nil {
  		log.Debug("Waiting for pollEvents() to stop...")
  		context.wg.Wait()
  		log.Debug("pollEvents() has stopped...")
  	} else {
  		log.WithField("err", err).Debug("NOT Waiting for pollEvents to stop...")
  	}
  
  	// Run cleanup for C-libmemif.
  	err = getMemifError(int(C.memif_cleanup()))
  	if err == nil {
  		context.initialized = false
  		log.Debug("libmemif library was closed")
  	}
  	return err
  }
docs: // Cleanup cleans up all the resources allocated by libmemif.