[GH-ISSUE #145] Lib trying to free image memory without image defined #118

Closed
opened 2026-05-05 11:42:44 -06:00 by gitea-mirror · 7 comments
Owner

Originally created by @ncfernan on GitHub (Jan 26, 2018).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/145

Originally assigned to: @jmcnamara on GitHub.

When using the function worksheet_insert_chart_opt the options parameters is copied to an internal structure that is shared with image functions, so when the program closes the workbook, the image points to dirty areas because no image was set.

If the options parameter is set to NULL, no problem arises.

lxw_image_options options;

options.x_offset = 0;
options.y_offset = 0;
options.x_scale  = 4.0;
options.y_scale  = 1.2;

worksheet_insert_chart_opt (worksheet, 1, col, chart, &options);

image

Originally created by @ncfernan on GitHub (Jan 26, 2018). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/145 Originally assigned to: @jmcnamara on GitHub. When using the function **worksheet_insert_chart_opt** the options parameters is copied to an internal structure that is shared with image functions, so when the program closes the workbook, the **image** points to dirty areas because no image was set. If the **options** parameter is set to NULL, no problem arises. ``` lxw_image_options options; options.x_offset = 0; options.y_offset = 0; options.x_scale = 4.0; options.y_scale = 1.2; worksheet_insert_chart_opt (worksheet, 1, col, chart, &options); ``` ![image](https://user-images.githubusercontent.com/10008844/35452435-9dffdaf2-02ad-11e8-896b-3419b4edc2d0.png)
gitea-mirror 2026-05-05 11:42:44 -06:00
Author
Owner

@ncfernan commented on GitHub (Jan 26, 2018):

I found the problem in worksheet.c:

image

<!-- gh-comment-id:360856730 --> @ncfernan commented on GitHub (Jan 26, 2018): I found the problem in **worksheet.c**: ![image](https://user-images.githubusercontent.com/10008844/35453393-39c1aa76-02b1-11e8-95a3-8a6e772624aa.png)
Author
Owner

@jmcnamara commented on GitHub (Jan 26, 2018):

Thanks for the report.

Could you add a small, compilable program that demonstrates the issue.

John

<!-- gh-comment-id:360873065 --> @jmcnamara commented on GitHub (Jan 26, 2018): Thanks for the report. Could you add a small, compilable program that demonstrates the issue. John
Author
Owner

@RaFaeL-NN commented on GitHub (Jan 29, 2018):

I sent out the same report a month ago. The problem is especially relevant when using the library with other programming languages in binary form. The best way is to split the options into two structures - one for external user use with 4 fields as a parameter, and the second one complete for internal

<!-- gh-comment-id:361171947 --> @RaFaeL-NN commented on GitHub (Jan 29, 2018): I sent out the same report a month ago. The problem is especially relevant when using the library with other programming languages in binary form. The best way is to split the options into two structures - one for external user use with 4 fields as a parameter, and the second one complete for internal
Author
Owner

@jmcnamara commented on GitHub (Jan 29, 2018):

@ncfernan You will need to initialize the lxw_image_options struct since it includes some non public members.

lxw_image_options options = {0};

However, I'll split the external and internal structs in a future release to avoid this type of issue.

<!-- gh-comment-id:361182677 --> @jmcnamara commented on GitHub (Jan 29, 2018): @ncfernan You will need to initialize the `lxw_image_options` struct since it includes some non public members. ```C lxw_image_options options = {0}; ``` However, I'll split the external and internal structs in a future release to avoid this type of issue.
Author
Owner

@jmcnamara commented on GitHub (Feb 4, 2018):

I've pushed a fix for this issue to the master branch. It will be in the next release.

<!-- gh-comment-id:362898271 --> @jmcnamara commented on GitHub (Feb 4, 2018): I've pushed a fix for this issue to the master branch. It will be in the next release.
Author
Owner

@ncfernan commented on GitHub (Feb 4, 2018):

Thank you, John. That was the best response for an issue that I've seen in a long time. Keep up the excellent work!

<!-- gh-comment-id:362938386 --> @ncfernan commented on GitHub (Feb 4, 2018): Thank you, John. That was the best response for an issue that I've seen in a long time. Keep up the excellent work!
Author
Owner

@jmcnamara commented on GitHub (Feb 4, 2018):

Thanks. :-)

<!-- gh-comment-id:362940402 --> @jmcnamara commented on GitHub (Feb 4, 2018): Thanks. :-)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#118
No description provided.