Skip to content

Fix: Memory leaks#575

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

Fix: Memory leaks#575
Piloalucard wants to merge 10 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
Copy link
Contributor

@amissael95 amissael95 left a comment

Choose a reason for hiding this comment

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

Thanks for working in this important change and addressing my comments. Approved!

Copy link
Collaborator

@syaoraang syaoraang left a comment

Choose a reason for hiding this comment

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

Overall it looks pretty good, just a few comments.

#define arch_vsprintf_auto( buffer, fmt, ...) arch_vsprintf(buffer,sizeof(buffer),fmt,__VA_ARGS__)

/*
These needs to be declared at the end to avoid redefinition and to avoid code replication
Copy link
Collaborator

Choose a reason for hiding this comment

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

"This needs..." instead of "These needs...", according to the context

Comment on lines +2072 to +2073
if(token)
arch_strncpy(work_buf+len+1, token, work_buf_len, strlen(token)); /* "/aaa/ccc/target.txt\0" */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please, use braces even on single-line ifs.

if (attr_data == NULL) return -LTFS_NO_MEMORY;
int attr_size = sizeof(char) * (attr_len + TC_MAM_PAGE_HEADER_SIZE);
attr_data = (unsigned char*)malloc(attr_size);
if (!attr_data) return -LTFS_NO_MEMORY;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use braces and line jumps for better readability.

{
const char name[] = "nametype", *value;
char *decoded_name, *encoded_name, *encode;
char* decoded_name = NULL, * encoded_name = NULL, * encode = NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

To have consistency, could you please use "char " instead of "char ", just a few lines below we are using "char *" , besides, it's most widely used across the code base

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.

3 participants