LLVMMemoryBufferRef MemBuf,
LLVMModuleRef *OutM, char **OutMessage);
-/** Reads a module from the specified path, returning via the OutMP parameter a
- * module provider which performs lazy deserialization. Returns 0 on success. */
+/** Reads a module from the given memory buffer, returning via the OutMP
+ * parameter a module provider which performs lazy deserialization.
+ *
+ * Returns 0 on success.
+ *
+ * Takes ownership of \p MemBuf if (and only if) the module was read
+ * successfully. */
LLVMBool LLVMGetBitcodeModuleInContext2(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf,
LLVMModuleRef *OutM);
LLVMModuleRef M;
int Ret = LLVMGetBitcodeModule2(MB, &M);
- if (Ret) {
- // We do not return if the bitcode was invalid, as we want to test whether
- // the diagnostic handler was executed.
- fprintf(stderr, "Error parsing bitcode: %s\n", msg);
- }
-
- LLVMDisposeMemoryBuffer(MB);
+ if (Ret)
+ LLVMDisposeMemoryBuffer(MB);
if (handlerCalled) {
fprintf(stderr, "Diagnostic handler was called while loading module\n");