Fix: Memory leaks#575
Fix: Memory leaks#575Piloalucard wants to merge 2 commits intoLinearTapeFileSystem:v2.4.8-windows-supportfrom
Conversation
src/libltfs/xml_reader_libltfs.c
Outdated
| { | ||
| const char name[] = "nametype", *value; | ||
| char *decoded_name, *encoded_name, *encode; | ||
| char *decoded_name=NULL, *encoded_name=NULL, *encode=NULL; |
There was a problem hiding this comment.
Please add spaces by using the next format <variable> = <value>
| 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); |
There was a problem hiding this comment.
Why are you using now WNLTFS? Just a name preference?
There was a problem hiding this comment.
"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; |
There was a problem hiding this comment.
Is that what you want? You are adding the header size to the pointer, an address returned by calloc, attr_data
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
See explanation above.
Summary of changes
This pull request includes following changes or fixes.
Type of change
Please delete items that are not relevant.
Checklist: