
int av_hwframe_ctx_init(AVBufferRef *ref)
{
+    if (ref == NULL) {
+        av_log(NULL, AV_LOG_ERROR, "Invalid NULL reference passed to av_hwframe_ctx_init\n");
+        return AVERROR(EINVAL);
+    }
     AVHWFramesContext *ctx = (AVHWFramesContext*)ref->data;
     // ... rest of the function
