Disposing unplaced IRP

Hi All,

I am new to this area and need your advice.
I have a situation where IRP has been prepared but not placed yet.

IRP* irp = IoAllocateIrp(device->StackSize,0);
after this, i am setting up other data members of IRP (RequestorMode,userEvent,Flags,completion routine …)
IO_STACK_LOCATION* irpSp = IoGetNextIrpStackLocation(irp);

I am not doing IoCallDriver on this IRP.

Later decided not to place this IRP. Now I need to come out of function. What step should i be doing:

  1. call IoFreeIrp(irp) to free up IRP and return
  2. dont need to do anything –> will memory allocated to IRP leak?
  3. Complete the IRP by calling IoCompleteRquest –> IRP has not been placed…this shouldn’t be needed?

Thanks,

xxxxx@gmail.com wrote:

I am new to this area and need your advice.
I have a situation where IRP has been prepared but not placed yet.

IRP* irp = IoAllocateIrp(device->StackSize,0);
after this, i am setting up other data members of IRP (RequestorMode,userEvent,Flags,completion routine …)
IO_STACK_LOCATION* irpSp = IoGetNextIrpStackLocation(irp);

I am not doing IoCallDriver on this IRP.

Later decided not to place this IRP. Now I need to come out of function. What step should i be doing:

  1. call IoFreeIrp(irp) to free up IRP and return
  2. dont need to do anything –> will memory allocated to IRP leak?
  3. Complete the IRP by calling IoCompleteRquest –> IRP has not been placed…this shouldn’t be needed?

You never, ever complete an IRP that you created. The IRP does not
contain a stack location for you, so completion causes you to trash memory.

You need to call IoFreeIrp.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

You must free the irp with IoFreeIrp. Think about it, even if you send the irp and it completes back to you, the completion routine must return STATUS_MORE_PROCESSING and you free the irp with IoFreeIrp. So sending the irp or not does not change what you must do.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Thursday, March 10, 2016 8:55 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Disposing unplaced IRP

Hi All,

I am new to this area and need your advice.
I have a situation where IRP has been prepared but not placed yet.

IRP* irp = IoAllocateIrp(device->StackSize,0);
after this, i am setting up other data members of IRP (RequestorMode,userEvent,Flags,completion routine …)
IO_STACK_LOCATION* irpSp = IoGetNextIrpStackLocation(irp);

I am not doing IoCallDriver on this IRP.

Later decided not to place this IRP. Now I need to come out of function. What step should i be doing:
1. call IoFreeIrp(irp) to free up IRP and return 2. dont need to do anything –> will memory allocated to IRP leak?
3. Complete the IRP by calling IoCompleteRquest –> IRP has not been placed…this shouldn’t be needed?

Thanks,


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

Thanks for answering this.
So the rule is when there is “IoAllocateIrp” , should always think of calling “IoFreeIrp” when done with the IRP. In my completion routine i do call it.