Comments (6)
if you look how function is written
https://github.com/libimobiledevice/libimobiledevice/blob/73b6fd183872096f20e6d1007429546a317a7cb1/src/afc.c#L513C13-L513C19
it internally call strdup ... eg. creates null terminated string duplicate, and returns pointer to it. since it's not structure there is no need for special handling, you just call free on returned pointer to string
https://en.cppreference.com/w/c/experimental/dynamic/strdup
from libimobiledevice.
if you look how function is written https://github.com/libimobiledevice/libimobiledevice/blob/73b6fd183872096f20e6d1007429546a317a7cb1/src/afc.c#L513C13-L513C19 it internally call strdup ... eg. creates null terminated string duplicate, and returns pointer to it. since it's not structure there is no need for special handling, you just call free on returned pointer to string https://en.cppreference.com/w/c/experimental/dynamic/strdup
I have tried this before, but it can cause the program to crash. Since I am using a dynamic link library (DLL) to call AFC_ Xxx ("libimobiledevice. ll" is also a dynamic DLL), and neither of them creates memory in the process stack area, so it does not follow the principle of "whoever creates memory should release it". In fact, the memory created by "afc_xxx" is in the module stack of "libimobile device. DLL", so I should use a "free" function in the "libimobile device. DLL" module to free up this memory.
from libimobiledevice.
Ah!!!! I mistakenly closed the issue o(╥﹏╥)o
from libimobiledevice.
if you look how function is written https://github.com/libimobiledevice/libimobiledevice/blob/73b6fd183872096f20e6d1007429546a317a7cb1/src/afc.c#L513C13-L513C19 it internally call strdup ... eg. creates null terminated string duplicate, and returns pointer to it. since it's not structure there is no need for special handling, you just call free on returned pointer to string https://en.cppreference.com/w/c/experimental/dynamic/strdup
I have tried this before, but it can cause the program to crash. Since I am using a dynamic link library (DLL) to call AFC_ Xxx ("libimobiledevice. ll" is also a dynamic DLL), and neither of them creates memory in the process stack area, so it does not follow the principle of "whoever creates memory should release it". In fact, the memory created by "afc_xxx" is in the module stack of "libimobile device. DLL", so I should use a "free" function in the "libimobile device. DLL" module to free up this memory.
are you sure, you releasing correct pointer? because it's created on global heap and following code works
char * keyval = nullptr;
if (afc_get_device_info_key(client, "requestedkey", &keyval) == AFC_E_SUCCESS && keyval) {
printf("%s", keyval);
free(keyval);
}
from libimobiledevice.
@mexmer you have to understand that Windows is really weird in all regards. So @Jack-Leey is right asking for a library free function. libplist already has one for the same reason.
from libimobiledevice.
@nikias i program under windows in c++ over 15 years. but now when i think of it, you both are right, should not have written answer late night.
for me the code works, because i use static compiled libimobile, so free is done in same process as allocation.
alltough there is a thing. if you use MSVC on windows, strdup memory allocation is internally implemented with HeapAlloc. if you will compile with gcc, or any other compiler, it will most likely use malloc and that's where problem lies. so to be safe, it's better to release pointer from dll as @Jack-Leey asks.
in win32api is quite common either use deallocate function (supplied by dll), or more common way is simply pass preallocated buffer from outside, and throw error if it's not big enough, or truncate data if possible.
from libimobiledevice.
Related Issues (20)
- Could not start service com.apple.mobilebackup2. HOT 4
- Developer Disk Images for iOS 17 HOT 1
- Unable to restore from backup HOT 1
- Can't install the library HOT 13
- 11
- iPhone 14 not found when launching idevicebackup2 from udev rule HOT 1
- ERROR: Could not start the simulatelocation service. Make sure a developer disk image is mounted! HOT 11
- MSYS2 libimobiledevice error.
- Weird size miscalculations HOT 1
- pull file from a app's sandbox catalog for iOS 17
- master fails to build with libressl 3.9.1 HOT 6
- Feature request: Any support plan for Vision Pro?
- files coming off of device twice HOT 4
- USBMUX keeps returning a broken pipe error
- ERROR: Could not connect to lockdownd, error code -8
- How to decrypt iTunes communication with iPhone?
- "idevicebackup2" .How to customize DLSMessageUploadFiles to only get the files I want HOT 1
- ideviceinfo shows wrong productType HOT 5
- ideviceinfo -q com.apple.disk_usage is showing wrong output of Storage value for iOS 17 HOT 3
- error when linking against so: `libimobiledevice`: missing symbols `userpref_get_paired_udids`, `userpref_read_pair_record` and `pair_record_get_host_id` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libimobiledevice.