~psusi/ubuntu/precise/dmraid/fix-gpt

« back to all changes in this revision

Viewing changes to 1.0.0.rc15/lib/mm/dbg_malloc.c

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2010-02-04 21:34:22 UTC
  • mfrom: (1.1.4 upstream) (2.4.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100204213422-tdag8lcxpr7ahmg4
Tags: 1.0.0.rc16-3ubuntu1
* Merge from debian testing. (LP: #503136)  Remaining changes:
  - debian/dmraid-activate: Remove the special-casing of the root
    device which breaks in many situations and leaves the raw devices
    exposed. This was introduced in Debian to accommodate some broken
    configurations which wanted to access "partitions" on the raid
    raw devices. In Ubuntu, broken configurations has not been supported.
  - debian/dmraid.postinst: Comment out "udevadm trigger" call in postinst
    for now as it has severeconsequences when mountall is installed
    (clears /tmp).  If dmraid is installed, then presumably the important
    system devices are up and one canbe bothered with a reboot to take 
    the change into account. Let update-initramfs flag the system
    as needing a reboot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2004,2005  Heinz Mauelshagen, Red Hat GmbH.
3
 
 *                          All rights reserved.
4
 
 *
5
 
 * See file LICENSE at the top of this source tree for license information.
6
 
 */
7
 
 
8
 
#include <string.h>
9
 
#include <stdlib.h>
10
 
#include <sys/types.h>
11
 
#include <stdint.h>
12
 
#include "dbg_malloc.h"
13
 
#include "log/log.h"
14
 
 
15
 
static void *
16
 
__dbg_malloc(size_t size, int init)
17
 
{
18
 
        void *ret = malloc(size);
19
 
 
20
 
        if (init && ret)
21
 
                memset(ret, 0, size);
22
 
 
23
 
        return ret;
24
 
}
25
 
 
26
 
#ifdef  DEBUG_MALLOC
27
 
 
28
 
void *
29
 
_dbg_malloc(size_t size, struct lib_context *lc,
30
 
            const char *who, unsigned int line)
31
 
{
32
 
        void *ret = __dbg_malloc(size, 1);
33
 
 
34
 
        log_dbg(lc, "%s: dbg_malloc(%zu) at line %u returned 0x%x",
35
 
                (char *) who, size, line, (unsigned long) ret);
36
 
 
37
 
        return ret;
38
 
}
39
 
 
40
 
void *
41
 
_dbg_realloc(void *ptr, size_t size, struct lib_context *lc,
42
 
             const char *who, unsigned int line)
43
 
{
44
 
        void *ret = realloc(ptr, size);
45
 
 
46
 
        log_dbg(lc, "%s: dbg_realloc(0x%x, %zu) at line %u returned 0x%x",
47
 
                (char *) who, (unsigned long) ptr, size, line,
48
 
                (unsigned long) ret);
49
 
 
50
 
        return ret;
51
 
}
52
 
 
53
 
void *
54
 
_dbg_strndup(void *ptr, size_t len, struct lib_context *lc,
55
 
             const char *who, unsigned int line)
56
 
{
57
 
        char *ret;
58
 
 
59
 
        if ((ret = __dbg_malloc(len + 1, 0))) {
60
 
                ret[len] = 0;
61
 
                strncpy(ret, ptr, len);
62
 
        }
63
 
 
64
 
        log_dbg(lc, "%s: dbg_strndup(0x%x) at line %u returned 0x%x",
65
 
                (char *) who, (unsigned long) ptr, line, (unsigned long) ret);
66
 
 
67
 
        return ret;
68
 
 
69
 
}
70
 
 
71
 
void *
72
 
_dbg_strdup(void *ptr, struct lib_context *lc,
73
 
            const char *who, unsigned int line)
74
 
{
75
 
        return _dbg_strndup(ptr, strlen(ptr), lc, who, line);
76
 
}
77
 
 
78
 
 
79
 
void
80
 
_dbg_free(void *ptr, struct lib_context *lc, const char *who, unsigned int line)
81
 
{
82
 
        log_dbg(lc, "%s: dbg_free(0x%x) at line %u",
83
 
                (char *) who, (unsigned long) ptr, line);
84
 
        free(ptr);
85
 
}
86
 
 
87
 
#else
88
 
 
89
 
void *
90
 
_dbg_malloc(size_t size)
91
 
{
92
 
        return __dbg_malloc(size, 1);
93
 
}
94
 
 
95
 
void *
96
 
_dbg_realloc(void *ptr, size_t size)
97
 
{
98
 
        return realloc(ptr, size);
99
 
}
100
 
 
101
 
void *
102
 
_dbg_strndup(void *ptr, size_t len)
103
 
{
104
 
        char *ret;
105
 
 
106
 
        if ((ret = __dbg_malloc(len + 1, 0))) {
107
 
                ret[len] = 0;
108
 
                strncpy(ret, ptr, len);
109
 
        }
110
 
 
111
 
        return ret;
112
 
}
113
 
 
114
 
void *
115
 
_dbg_strdup(void *ptr)
116
 
{
117
 
        return _dbg_strndup(ptr, strlen(ptr));
118
 
}
119
 
 
120
 
void
121
 
_dbg_free(void *ptr)
122
 
{
123
 
        free(ptr);
124
 
}
125
 
 
126
 
#endif /* #ifdef DEBUG_MALLOC */