Skip to contentSkip to conversation

libgfs2: Fix resource leak in lgfs2_lang_result()

PATCH New Paul Evans 2 participants 2 messages Jul 2, 2013

lore
Share & tools
lore

Paul Evans

author
#0 lore raw

PATCH 1/1 libgfs2: Fix resource leak in lgfs2_lang_result()

Spotted by coverity: Resource leak, variable "result" going out of scope and leaking the storage it points to.

Variable "result" is now free'd before returning.

---
 gfs2/libgfs2/lang.c | 1 +
 1 file changed, 1 insertion(+)
gfs2/libgfs2/lang.c +1 -0
index 28805b5..3cc5f29 100644
@@ -421,6 +421,7 @@ static struct lgfs2_lang_result *ast_interp_get(struct lgfs2_lang_state *state,
 	} else if (ast->ast_right->ast_right->ast_type == AST_KW_STATE) {
 		result->lr_blocknr = ast_lookup_block_num(ast->ast_right, sbd);
 		if (result->lr_blocknr == 0) {
+                        free(result);
 			return NULL;
 		}
 		result->lr_state = ast_get_bitstate(result->lr_blocknr, sbd);
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH 1/1 libgfs2: Fix resource leak in lgfs2_lang_result()

Hi Paul,

Quoted 6 lines · Paul Evans

Spotted by coverity: Resource leak, variable "result" going out of scope and leaking the storage it points to.

Variable "result" is now free'd before returning.

Looks good to me.

gfs2/libgfs2/lang.c static struct lgfs2_lang_result *ast_interp_get(struct lgfs2_lang_state *state, · line 424

Quoted 13 lines
---
  gfs2/libgfs2/lang.c | 1 +
  1 file changed, 1 insertion(+)
gfs2/libgfs2/lang.c +1 -0
index 28805b5..3cc5f29 100644
@@ -421,6 +421,7 @@ static struct lgfs2_lang_result *ast_interp_get(struct lgfs2_lang_state *state,
  	} else if (ast->ast_right->ast_right->ast_type == AST_KW_STATE) {
  		result->lr_blocknr = ast_lookup_block_num(ast->ast_right, sbd);
  		if (result->lr_blocknr == 0) {
+                        free(result);

Just a style nit: please use tabs for indentation and spaces for alignment.

Cheers,
Andy

Quoted 4 lines
gfs2/libgfs2/lang.c +0 -0
  			return NULL;
  		}
  		result->lr_state = ast_get_bitstate(result->lr_blocknr, sbd);