diff --git a/src/ar.h b/src/ar.h index 5d5ce6e8c..edb71619f 100644 --- a/src/ar.h +++ b/src/ar.h @@ -164,12 +164,11 @@ class MemoryReader { MemoryReader(uint8* buffer, int size) : buffer_(buffer), size_(size) {} /// Fills the next file. - /// On success, the name of the file is allocated and should be freed with - /// 'free'. + /// On success, the file's name is automatically freed when the 'file' + /// is reused or the destructor is called. /// On success, the content of the file is pointing directly into the memory /// that was given at construction. /// - /// /// Returns 0 when a file was successfully read. /// /// Returns [AR_END_OF_ARCHIVE] when at the end of the archive. @@ -221,7 +220,8 @@ class FileReader { /// /// Returns 0 when a file was successfully read. /// In this case: - /// - The name of the file is allocated and should be freed with 'free'. + /// - The name of the file is automatically freed when the 'file' is + /// reused or its destructor is called. /// - The content of the file is allocated and should be freed with 'free'. /// /// Returns [AR_END_OF_ARCHIVE] when at the end of the archive. @@ -238,6 +238,9 @@ class FileReader { /// If [reset] is true, starts searching at the beginning of the file. This /// requires the file to be seekable. /// + /// The name and the content of the result are automatically freed when + /// the file is reused or the destructor is called. + /// /// Returns 0 when a file was successfully read. /// In that case: /// - The name of the file is pointing to the given [name]. diff --git a/src/snapshot_bundle.cc b/src/snapshot_bundle.cc index 56e00b1b4..118860142 100644 --- a/src/snapshot_bundle.cc +++ b/src/snapshot_bundle.cc @@ -163,7 +163,12 @@ SnapshotBundle SnapshotBundle::stripped() const { // The const cast should be safe. snapshot_bytes = List(const_cast(file.content()), file.byte_size); } else if (strcmp(file.name(), SDK_VERSION_NAME) == 0) { - sdk_version = reinterpret_cast(file.content()); + // Copy the sdk-version so it's null terminated. + int sdk_len = file.byte_size; + char* buffer = unvoid_cast(malloc(sdk_len + 1)); + memcpy(buffer, file.content(), sdk_len); + buffer[sdk_len] = '\0'; + sdk_version = buffer; } } return SnapshotBundle(snapshot_bytes, null, null, null, sdk_version);