requester: Add null check in pldm_instance_id_alloc

pldm_instance_id_alloc() function does not check for a valid
ctx object before dereferencing it. Hence it could cause
crash when its clients pass a null pointer by accident.

Change-Id: I340aa8171cd397f5af772a9cc6d4f80c8263a089
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
diff --git a/tests/instance-id.cpp b/tests/instance-id.cpp
index ad290ac..ed94c59 100644
--- a/tests/instance-id.cpp
+++ b/tests/instance-id.cpp
@@ -86,6 +86,14 @@
     EXPECT_EQ(pldm_instance_db_destroy(db), 0);
 }
 
+TEST_F(PldmInstanceDbTest, allocOnNulldb)
+{
+    struct pldm_instance_db* db = nullptr;
+    const pldm_tid_t tid = 1;
+    pldm_instance_id_t iid;
+    EXPECT_EQ(pldm_instance_id_alloc(db, tid, &iid), -EINVAL);
+}
+
 TEST_F(PldmInstanceDbTest, allocFreeOne)
 {
     struct pldm_instance_db* db = nullptr;