Coverage Report

Created: 2026-06-07 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/imagemagick/Magick++/lib/BlobRef.cpp
Line
Count
Source
1
// This may look like C code, but it is really -*- C++ -*-
2
//
3
// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2004
4
//
5
// Copyright @ 2014 ImageMagick Studio LLC, a non-profit organization
6
// dedicated to making software imaging solutions freely available.
7
//
8
// Implementation of Blob
9
//
10
11
#define MAGICKCORE_IMPLEMENTATION  1
12
#define MAGICK_PLUSPLUS_IMPLEMENTATION 1
13
14
#include "Magick++/Include.h"
15
#include "Magick++/BlobRef.h"
16
#include "Magick++/Exception.h"
17
#include "Magick++/Thread.h"
18
19
#include <string.h>
20
21
Magick::BlobRef::BlobRef(const void* data_,const size_t length_)
22
705k
  : allocator(Magick::Blob::NewAllocator),
23
705k
    length(length_),
24
705k
    data((void*) NULL),
25
705k
    _mutexLock(),
26
705k
    _refCount(1)
27
705k
{
28
705k
  if (data_ != (const void*) NULL)
29
570k
    {
30
570k
      data=new unsigned char[length_];
31
570k
      memcpy(data,data_,length_);
32
570k
    }
33
705k
}
34
35
Magick::BlobRef::~BlobRef(void)
36
705k
{
37
705k
  if (allocator == Magick::Blob::NewAllocator)
38
639k
    {
39
639k
      delete[] static_cast<unsigned char*>(data);
40
639k
      data=(void *) NULL;
41
639k
    }
42
65.5k
  else if (allocator == Magick::Blob::MallocAllocator)
43
65.5k
    data=(void *) RelinquishMagickMemory(data);
44
705k
}
45
46
size_t Magick::BlobRef::decrease()
47
705k
{
48
705k
  size_t
49
705k
    count;
50
51
705k
  _mutexLock.lock();
52
705k
  if (_refCount == 0)
53
0
    {
54
0
      _mutexLock.unlock();
55
0
      throwExceptionExplicit(MagickCore::OptionError,
56
0
        "Invalid call to decrease");
57
0
      return(0);
58
0
    }
59
705k
  count=--_refCount;
60
705k
  _mutexLock.unlock();
61
705k
  return(count);
62
705k
}
63
64
void Magick::BlobRef::increase()
65
0
{
66
0
  _mutexLock.lock();
67
0
  _refCount++;
68
0
  _mutexLock.unlock();
69
0
}