Add some missing checks of SCMalloc return.

pull/91/head
Eric Leblond 14 years ago
parent d8667448c1
commit 655577cbbc

@ -156,9 +156,11 @@ static DetectFileextData *DetectFileextParse (char *str)
#ifdef DEBUG
if (SCLogDebugEnabled()) {
char *ext = SCMalloc(fileext->len + 1);
memcpy(ext, fileext->ext, fileext->len);
ext[fileext->len] = '\0';
SCLogDebug("will look for fileext %s", ext);
if (ext != NULL) {
memcpy(ext, fileext->ext, fileext->len);
ext[fileext->len] = '\0';
SCLogDebug("will look for fileext %s", ext);
}
}
#endif

@ -167,9 +167,11 @@ static int DetectFilemagicMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx,
#ifdef DEBUG
if (SCLogDebugEnabled()) {
char *name = SCMalloc(filemagic->len + 1);
memcpy(name, filemagic->name, filemagic->len);
name[filemagic->len] = '\0';
SCLogDebug("will look for filemagic %s", name);
if (name != NULL) {
memcpy(name, filemagic->name, filemagic->len);
name[filemagic->len] = '\0';
SCLogDebug("will look for filemagic %s", name);
}
}
#endif
@ -222,9 +224,11 @@ static DetectFilemagicData *DetectFilemagicParse (char *str)
#ifdef DEBUG
if (SCLogDebugEnabled()) {
char *name = SCMalloc(filemagic->len + 1);
memcpy(name, filemagic->name, filemagic->len);
name[filemagic->len] = '\0';
SCLogDebug("will look for filemagic %s", name);
if (name != NULL) {
memcpy(name, filemagic->name, filemagic->len);
name[filemagic->len] = '\0';
SCLogDebug("will look for filemagic %s", name);
}
}
#endif

@ -109,9 +109,11 @@ static int DetectFilenameMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx,
#ifdef DEBUG
if (SCLogDebugEnabled()) {
char *name = SCMalloc(filename->len + 1);
memcpy(name, filename->name, filename->len);
name[filename->len] = '\0';
SCLogDebug("will look for filename %s", name);
if (name != NULL) {
memcpy(name, filename->name, filename->len);
name[filename->len] = '\0';
SCLogDebug("will look for filename %s", name);
}
}
#endif
@ -165,9 +167,11 @@ static DetectFilenameData *DetectFilenameParse (char *str)
#ifdef DEBUG
if (SCLogDebugEnabled()) {
char *name = SCMalloc(filename->len + 1);
memcpy(name, filename->name, filename->len);
name[filename->len] = '\0';
SCLogDebug("will look for filename %s", name);
if (name != NULL) {
memcpy(name, filename->name, filename->len);
name[filename->len] = '\0';
SCLogDebug("will look for filename %s", name);
}
}
#endif

@ -470,6 +470,9 @@ int SCCudaHlGetCudaModule(CUmodule *p_module, const char *ptx_image, int handle)
/* select the ptx image based on the compute capability supported by all
* devices (i.e. the lowest) */
char* image = SCMalloc(strlen(ptx_image)+15);
if (image == NULL) {
exit(EXIT_FAILURE);
}
memset(image, 0x0, sizeof(image));
int major = INT_MAX;

@ -116,9 +116,9 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void *
uint32_t u32 = 0;
if (size > 0) {
PoolBucket *pb = SCCalloc(size, sizeof(PoolBucket));
p->pb_buffer = pb;
if (pb == NULL)
if (unlikely(pb == NULL))
goto error;
p->pb_buffer = pb;
memset(pb, 0, size * sizeof(PoolBucket));
for (u32 = 0; u32 < size; u32++) {
/* populate pool */
@ -350,6 +350,8 @@ void PoolPrintSaturation(Pool *p) {
void *PoolTestAlloc() {
void *ptr = SCMalloc(10);
if (ptr == NULL)
return NULL;
return ptr;
}
int PoolTestInitArg(void *data, void *allocdata) {

@ -168,6 +168,10 @@ void SCProfilingRulesGlobalInit(void) {
log_dir = DEFAULT_LOG_DIR;
profiling_file_name = SCMalloc(PATH_MAX);
if (profiling_file_name == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "can't duplicate file name");
exit(EXIT_FAILURE);
}
snprintf(profiling_file_name, PATH_MAX, "%s/%s", log_dir, filename);
const char *v = ConfNodeLookupChildValue(conf, "append");

@ -141,6 +141,11 @@ SCProfilingInit(void)
log_dir = DEFAULT_LOG_DIR;
profiling_packets_file_name = SCMalloc(PATH_MAX);
if (profiling_packets_file_name == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "can't duplicate file name");
exit(EXIT_FAILURE);
}
snprintf(profiling_packets_file_name, PATH_MAX, "%s/%s", log_dir, filename);
const char *v = ConfNodeLookupChildValue(conf, "append");
@ -215,6 +220,11 @@ SCProfilingInit(void)
log_dir = DEFAULT_LOG_DIR;
profiling_locks_file_name = SCMalloc(PATH_MAX);
if (profiling_locks_file_name == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "can't duplicate file name");
exit(EXIT_FAILURE);
}
snprintf(profiling_locks_file_name, PATH_MAX, "%s/%s", log_dir, filename);
const char *v = ConfNodeLookupChildValue(conf, "append");

@ -33,6 +33,8 @@ void setenv(const char *name, const char *value, int overwrite)
{
if (overwrite || NULL == getenv(name)) {
char *str = SCMalloc(strlen(name) + strlen(value) + 2);
if (str == NULL)
return;
snprintf(str, strlen(name) + strlen(value) + 1, "%s=%s", name, value);
putenv(str);
SCFree(str);
@ -42,6 +44,8 @@ void setenv(const char *name, const char *value, int overwrite)
void unsetenv(const char *name)
{
char *str = SCMalloc(strlen(name) + 2);
if (str == NULL)
return;
snprintf(str, strlen(name) + 1, "%s=", name);
putenv(str);
SCFree(str);

Loading…
Cancel
Save