Arjen de Korte
2007-Feb-16 08:50 UTC
[Nut-upsdev] Re: [nut-commits] svn commit r808 - in trunk: . drivers
> next_device: > + free(curDevice->Vendor); > + free(curDevice->Product); > + free(curDevice->Serial); > + free(curDevice->Bus); > usb_close(udev); > udev = NULL; > }Wouldn't it be necessary to check whether there is anything to free or not? Vendor, Product and Serial are set conditionally. In the lines upsdebugx(2, "- Manufacturer: %s", curDevice->Vendor ? curDevice->Vendor : "unknown"); upsdebugx(2, "- Product: %s", curDevice->Product ? curDevice->Product : "unknown"); upsdebugx(2, "- Serial Number: %s", curDevice->Serial ? curDevice->Serial : "unknown"); we apparently are not sure that Vendor, Product and Serial contain were set too, so we might risk trying to free NULL pointers here. Best regards, Arjen -- Eindhoven - The Netherlands Key fingerprint - 66 4E 03 2C 9D B5 CB 9B 7A FE 7E C1 EE 88 BC 57
Arjen de Korte
2007-Feb-16 09:00 UTC
[Nut-upsdev] Re: [nut-commits] svn commit r808 - in trunk: . drivers
> Wouldn't it be necessary to check whether there is anything to free or > not? Vendor, Product and Serial are set conditionally.You already answered that yourself ahead of me asking, apologies for all the noise. All others, 'IEEE Std 1003.1, 2004 Edition' says "The free() function shall cause the space pointed to by ptr to be deallocated; that is, made available for further allocation. If ptr is a null pointer, no action shall occur." We do use the check for NULL pointers before freeing them throughout the so I think I have a little task for this weekend (clearing out all superfluous checks for NULL pointers). Best regards, Arjen