Skip to content

Fix: Memory leaks#575

Open
Piloalucard wants to merge 2 commits intoLinearTapeFileSystem:v2.4.8-windows-supportfrom
Piloalucard:fix/memory-leaks
Open

Fix: Memory leaks#575
Piloalucard wants to merge 2 commits intoLinearTapeFileSystem:v2.4.8-windows-supportfrom
Piloalucard:fix/memory-leaks

Conversation

@Piloalucard
Copy link
Member

Summary of changes

This pull request includes following changes or fixes.

  • Fixes memory leak on src/libltfs/fs.c
  • Fixes memory leak on src/libltfs/xml.h by re-defining declare_tracking_arrays implementation. If called and no optional tags are required will use declare_tracking_arrays_no_opt. If called and no tags are required will use declare_tracking_arrays_no_tags
  • Fixes tape_set_attribute_to_cm memory buffer wrong size.
  • Fixes tape_get_attribute_from_cm memory buffer wrong size
  • Deletes arch_strcpy_limited from src/libltfs/arch/ltfs_arch_ops.h
  • Ensures usages for Windows/Linux implementation of arch_strcpy and arch_strncpy

Type of change

Please delete items that are not relevant.

  • Refactoring
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have confirmed my fix is effective or that my feature works

@Piloalucard Piloalucard changed the base branch from master to v2.4.8-windows-support March 5, 2026 20:35
{
const char name[] = "nametype", *value;
char *decoded_name, *encoded_name, *encode;
char *decoded_name=NULL, *encoded_name=NULL, *encode=NULL;
Copy link
Contributor

@amissael95 amissael95 Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add spaces by using the next format <variable> = <value>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thank you

memset(key, 0x00, KEYLEN);
*key = KEY_PREFIX_HOST;
arch_strncpy_auto(key + 1, "WINLTFS", KEYLEN - 1);
arch_strncpy(key + 1, "WNLTFS", KEYLEN - 1,KEYLEN-2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using now WNLTFS? Just a name preference?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"WINLTFS" takes 7 character, and it starts writing in position 1, so it will no have space for the null character on the buffer cause it is an 8 byte buffer.
I found "WNLTFS" still accomplish the intended objective and leaves space for the null character. Do you have another proposal?

attr_data[2] = format; /* set data format type */
ltfs_u16tobe(attr_data + 3, attr_size); /* set data size */

data = attr_data + TC_MAM_PAGE_HEADER_SIZE;
Copy link
Contributor

@amissael95 amissael95 Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that what you want? You are adding the header size to the pointer, an address returned by calloc, attr_data

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
Addresses are hexadecimal, integer values. Adding in this context by 1 means the address augments 1 byte as of:

  • Address A = 0x09
  • Address B = Null
  • Address B = Address A + 1 = 0x0A

So we write starting on the first position of our given memory address, it is an offset.

We add the memory header size to start writing in the buffer after the header size, which space is being occupied by the header.

It was refactored for readability.

switch (type) {
case TC_MAM_APP_VENDER:
len = strnlen(t_attr->vender, attr_size);
memcpy(data, t_attr->vender, len);
Copy link
Contributor

@amissael95 amissael95 Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are copying the value pointer by "vender" to the "data" pointer you previously defined as the address returned by calloc + 0x5 (header size), please check and clarify.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See explanation above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants