Skip to content

Figure out if error cases around AP4_FileByteStream::Create need to release the stream #4

Description

@SingingTree

If a file byte stream fails creation fails, should the stream be released? There seems to be mixed messaging around this. E.g. Mp4Edit.cpp has

    result = AP4_FileByteStream::Create(output_filename, AP4_FileByteStream::STREAM_MODE_WRITE, output);
    if (AP4_FAILED(result)) {
        fprintf(stderr, "ERROR: cannot open output file (%s)\n", output_filename);
        input->Release();
        return 1;
    }

I.e. yes, the stream should be released (input->Release();).

However, from Mp4Dump.cpp

    AP4_Result result = AP4_FileByteStream::Create(dump_filename, AP4_FileByteStream::STREAM_MODE_WRITE, output);
    if (AP4_FAILED(result)) {
        fprintf(stderr, "ERROR: %d cannot open file for dumping track %d", 
                result, track_id);
    }

no release is performed.

Maybe worth upstreaming something once it's clear which should be done. If nothing else it could be worth documenting in Ap4FileByteStream.h, which currently doesn't mention what should be done.

   /**
     * Create a stream from a file (opened or created).
     *
     * @param name Name of the file to open or create
     * @param mode Mode to use for the file
     * @param stream Reference to a pointer where the stream object will
     * be returned
     * @return AP4_SUCCESS if the file can be opened or created, or an error code if
     * it cannot
     */
    static AP4_Result Create(const char* name, Mode mode, AP4_ByteStream*& stream);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions