| Ticket UUID: | 25894d41c28e81bd8dbda8032cfdce128842bdd7 | |||
| Title: | correcting usage of Tk_FreeColor() in ImgPhotoCmd() | |||
| Type: | Patch | Version: | 8.6.12 | |
| Submitter: | chrstphrchvz | Created on: | 2021-12-09 01:11:35 | |
| Subsystem: | 41. Photo Images | Assigned To: | jan.nijtmans | |
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Closed | Last Modified: | 2021-12-10 12:32:53 | |
| Resolution: | Fixed | Closed By: | jan.nijtmans | |
| Closed on: | 2021-12-10 12:32:53 | |||
| Description: |
In ImgPhotoCmd() (generic/tkImgPhoto.c), options.background is initialized* to NULL by memset(&options, 0, sizeof(options)). In the PHOTO_DATA and PHOTO_WRITE cases, options.background is then possibly set by ParseSubcommandOptions(&options, interp, OPT_BACKGROUND | …, …). If it is set, it should eventually be freed using Tk_FreeColor(options.background). *(assuming NULL is 0 at runtime—it may be more proper to manually initialize options.background by assigning NULL, or to instead use (options.options & OPT_BACKGROUND) to check whether it was set.) However, there are instances where ImgPhotoCmd() returns early without freeing options.background, and there are instances where Tk_FreeColor(options.background) is unreachable because options.background is never set (i.e. cases where ParseSubcommandOptions() is not called with OPT_BACKGROUND). Example commands which cause options.background to not be freed: Correcting Tk_FreeColor() usage seems straightforward; see attached patch. But would it be preferable to instead organize each switch case in ImgPhotoCmd() better to prevent missing/extraneous Tk_FreeColor() usage, e.g. single exit point (at least per switch case)?% image create photo image1 -width 1 -height 1 % image1 data file.out -background blue wrong # args: should be "image1 data ?-option value ...?" | |||
| User Comments: |
jan.nijtmans added on 2021-12-10 12:32:53:
Merged to all branches now. Closing jan.nijtmans added on 2021-12-09 17:13:45: Committed to its own branch now: [4959f1796bf88556] I cannot see anything wrong in it, but if someone else wants to review .... | |||
Attachments:
- 25894d41c2.diff [download] added by chrstphrchvz on 2021-12-09 01:12:28. [details]
