diff --git a/lustre/ldlm/ldlm_lock.c b/lustre/ldlm/ldlm_lock.c
index b63aaba665f92fada1a71192ddf3ca373f8cc5c8..94be0f770c0c1e030eb3698c65450a97a06893dd 100644
--- a/lustre/ldlm/ldlm_lock.c
+++ b/lustre/ldlm/ldlm_lock.c
@@ -383,10 +383,8 @@ int ldlm_lock_change_resource(struct ldlm_namespace *ns, struct ldlm_lock *lock,
         unlock_res_and_lock(lock);
 
         newres = ldlm_resource_get(ns, NULL, new_resid, type, 1);
-        if (newres == NULL) {
-                LBUG();
+        if (newres == NULL)
                 RETURN(-ENOMEM);
-        }
 
         lock_res_and_lock(lock);
         LASSERT(memcmp(&new_resid, &lock->l_resource->lr_name,
diff --git a/lustre/ldlm/ldlm_lockd.c b/lustre/ldlm/ldlm_lockd.c
index 80ec0488f00ad2c88df97007408cd56f3729f4f6..4a732702f29dc478c89031a7373d648a738791c5 100644
--- a/lustre/ldlm/ldlm_lockd.c
+++ b/lustre/ldlm/ldlm_lockd.c
@@ -1353,8 +1353,13 @@ static void ldlm_handle_cp_callback(struct ptlrpc_request *req,
                    &lock->l_resource->lr_name,
                    sizeof(lock->l_resource->lr_name)) != 0) {
                 unlock_res_and_lock(lock);
-                ldlm_lock_change_resource(ns, lock,
-                                         dlm_req->lock_desc.l_resource.lr_name);
+                if (ldlm_lock_change_resource(ns, lock, 
+                                dlm_req->lock_desc.l_resource.lr_name)) {
+                        LDLM_ERROR(lock, "Failed to allocate resource");
+                        LDLM_LOCK_PUT(lock);
+                        EXIT;
+                        return;
+                }
                 LDLM_DEBUG(lock, "completion AST, new resource");
                 CERROR("change resource!\n");
                 lock_res_and_lock(lock);
diff --git a/lustre/ldlm/ldlm_request.c b/lustre/ldlm/ldlm_request.c
index aa3d1ae7b2da664e712ce672f94d87fde6774ce4..0dcd78159a72d31d48f8e815529bcd260781ba7f 100644
--- a/lustre/ldlm/ldlm_request.c
+++ b/lustre/ldlm/ldlm_request.c
@@ -440,12 +440,10 @@ int ldlm_cli_enqueue_fini(struct obd_export *exp, struct ptlrpc_request *req,
                               (long)reply->lock_desc.l_resource.lr_name.name[0],
                                (long)lock->l_resource->lr_name.name[0]);
 
-                        ldlm_lock_change_resource(ns, lock,
+                        rc = ldlm_lock_change_resource(ns, lock,
                                            reply->lock_desc.l_resource.lr_name);
-                        if (lock->l_resource == NULL) {
-                                LBUG();
+                        if (rc || lock->l_resource == NULL)
                                 GOTO(cleanup, rc = -ENOMEM);
-                        }
                         LDLM_DEBUG(lock, "client-side enqueue, new resource");
                 }
                 if (with_policy)