There were a few places where we didn't check malloc return code.
Signed-off-by: Yehuda Sadeh <yehuda@hq.newdream.net>
size_t sz = 1024; // just a guess, template names will go much wider
char *function = (char *)malloc(sz);
+ if (!function)
+ return;
char *begin = 0, *end = 0;
// find the parentheses and address offset surrounding the mangled name
if (begin && end) {
int len = end - begin;
char *foo = (char *)malloc(len+1);
+ if (!foo)
+ return;
memcpy(foo, begin, len);
foo[len] = 0;
sz = (size_t)st_buf.st_size;
buf = (char*)malloc(sz);
+ if (!buf) {
+ ret = -ENOMEM;
+ goto done;
+ }
if (fread(buf, 1, sz, fp) != sz) {
if (ferror(fp)) {
stacksize &= CEPH_PAGE_MASK; // must be multiple of page
if (stacksize) {
thread_attr = (pthread_attr_t*) malloc(sizeof(pthread_attr_t));
+ if (!thread_attr)
+ return -ENOMEM;
pthread_attr_init(thread_attr);
pthread_attr_setstacksize(thread_attr, stacksize);
}
class buffer::raw_malloc : public buffer::raw {
public:
raw_malloc(unsigned l) : raw(l) {
- if (len)
+ if (len) {
data = (char *)malloc(len);
- else
+ if (!data)
+ throw bad_alloc();
+ } else {
data = 0;
+ }
inc_total_alloc(len);
bdout << "raw_malloc " << this << " alloc " << (void *)data << " " << l << " " << buffer::get_total_alloc() << bendl;
}
if (argc && argv)
myname = argv[0];
argv = (const char**)malloc(sizeof(char*) * argc);
+ if (!argv)
+ throw bad_alloc();
argc = 1;
argv[0] = myname;
int l = strlen(str.c_str()) + 1;
if (len == -1) {
*buf = (char*)malloc(l);
+ if (!*buf)
+ return -ENOMEM;
strcpy(*buf, str.c_str());
return 0;
}
len = BUF_SIZE;
new_str = (char *)malloc(len);
+ if (!new_str)
+ return NULL;
pos = 0;
/* Expand each slash-separated pathname component. */
link_path = malloc(PATH_MAX+1);
+ if (!link_path)
+ return NULL;
while (*path != '\0') {
/* Ignore stray "/" */
if (*path == '/') {
return NULL;
canonical = malloc(PATH_MAX+2);
+ if (!canonical)
+ return NULL;
if (!myrealpath(path, canonical, PATH_MAX+1)) {
free(canonical);
return strdup(path);
r = (*pctx)->pg->do_osd_ops(*pctx, nops);
*outdata = (char *)malloc(op.outdata.length());
+ if (!*outdata)
+ return -ENOMEM;
memcpy(*outdata, op.outdata.c_str(), op.outdata.length());
*outdatalen = op.outdata.length();
r = (*pctx)->pg->do_osd_ops(*pctx, nops);
*outdata = (char *)malloc(op.outdata.length());
+ if (!*outdata)
+ return -ENOMEM;
memcpy(*outdata, op.outdata.c_str(), op.outdata.length());
*outdatalen = op.outdata.length();
int r = (*pctx)->pg->do_osd_ops(*pctx, ops);
*outdata = (char *)malloc(ops[0].outdata.length());
+ if (!*outdata)
+ return -ENOMEM;
memcpy(*outdata, ops[0].outdata.c_str(), ops[0].outdata.length());
*outdatalen = ops[0].outdata.length();